home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SNNSV32.ZIP / SNNSv3.2 / kernel / sources / kr_ui.c < prev    next >
C/C++ Source or Header  |  1994-04-25  |  131KB  |  4,380 lines

  1. /*****************************************************************************
  2.   FILE           : kr_ui.c
  3.   SHORTNAME      : kr_ui.c
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : SNNS-Kernel User Interface
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Niels Mache
  10.   DATE           : 27.02.90
  11.  
  12.   CHANGED BY     : Michael Vogt, Guenter Mamier
  13.   IDENTIFICATION : @(#)kr_ui.c    1.25 4/12/94
  14.   SCCS VERSION   : 1.25
  15.   LAST CHANGE    : 4/12/94
  16.  
  17.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  18.  
  19. ******************************************************************************/
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <time.h>
  23. #include <string.h>
  24. #include <memory.h>
  25.  
  26. #ifndef rand
  27. #include "random.h"     /*  Randomize Library Function Prototypes  */
  28. #endif
  29.  
  30. #include "kr_typ.h"     /*  Kernel Types and Constants  */
  31. #include "glob_typ.h"
  32. #include "kr_const.h"     /*  Constant Declarators for SNNS-Kernel  */
  33. #include "kr_def.h"     /*  Default Values  */
  34.  
  35. #include "kr_io.h"     /*  Kernel I/O-Routines */
  36. #include "kr_funcs.h"    /*  Function Prototypes */
  37. #include "kernel.h"     /*  Function Prototypes */
  38. #include "kr_mem.h"      /*  Function Prototypes */
  39. #include "kr_ui.ph"     /*  Interface function prototypes  */
  40. #include "version.h"     /*  Version and Patchlevel  */
  41. #include "kr_mac.h"     /*  Kernel Macros  */
  42. #include "kr_newpattern.h"   /* new style pattern handling */
  43. #include "kr_inversion.h" /* inversion algorithm routines */
  44.  
  45. #ifdef MASPAR_KERNEL
  46.  
  47. #include "kr_feedf.h"     /*  Function Prototypes */
  48.  
  49. #endif
  50.  
  51. /*****************************************************************************
  52.   FUNCTION : krui_getNoOfUnits
  53.  
  54.   PURPOSE  : 
  55.   NOTES    :
  56.  
  57.   RETURNS  : Returns the number of units used by the network.
  58.   UPDATE   : 
  59. ******************************************************************************/
  60. int     krui_getNoOfUnits(void)
  61. {
  62.   return( NoOfUnits );
  63. }
  64.  
  65.  
  66. /*****************************************************************************
  67.   FUNCTION : krui_getFirstUnit
  68.  
  69.   PURPOSE  : Initializes the first available unit for access. If the unit has 
  70.              sites, the first site will be set to the current site.
  71.   NOTES    :
  72.  
  73.   RETURNS  : Returns the unit no. of the first unit or 0 if no units available.
  74.   UPDATE   : 
  75. ******************************************************************************/
  76. int  krui_getFirstUnit(void)
  77. {
  78.   return( kr_getUnit( FIRST ) );
  79. }
  80. /*****************************************************************************
  81.   FUNCTION : krui_getNextUnit
  82.  
  83.   PURPOSE  : Initializes the next available unit for access. If the unit has sites, the
  84.              first site will be set to the current site.
  85.   NOTES    :
  86.  
  87.   RETURNS  : Returns the unit no. of the next unit or 0 if no more units available.
  88.   UPDATE   : 
  89. ******************************************************************************/
  90. int  krui_getNextUnit(void)
  91. {
  92.   return( kr_getUnit( NEXT ) );
  93. }
  94.  
  95. /*****************************************************************************
  96.   FUNCTION : krui_getCurrentUnit
  97.  
  98.   PURPOSE  :
  99.   NOTES    :
  100.  
  101.   RETURNS  : Returns the no. of the current unit or 0 if no units available
  102.   UPDATE   : 
  103. ******************************************************************************/
  104. int  krui_getCurrentUnit(void)
  105. {
  106.   return( kr_getUnit( CURRENT ) );
  107. }
  108.  
  109. /*****************************************************************************
  110.   FUNCTION : krui_setCurrentUnit
  111.  
  112.   PURPOSE  : Initializes a unit for access. If the unit has sites, the first site
  113.     will be set to the current site.
  114.   NOTES    :
  115.  
  116.   RETURNS  : Returns error code if the given unit doesn't exist, 0 otherwise.
  117.   UPDATE   : 
  118. ******************************************************************************/
  119. krui_err  krui_setCurrentUnit(int unit_no)
  120. {
  121.   return( kr_setCurrUnit( unit_no ) );
  122. }
  123.  
  124. /*****************************************************************************
  125.   FUNCTION : krui_getUnitName
  126.  
  127.   PURPOSE  : 
  128.   NOTES    :
  129.  
  130.   RETURNS  : Returns the name of the unit. (NULL if not available)
  131.   UPDATE   : 
  132. ******************************************************************************/
  133. char  *krui_getUnitName(int UnitNo)
  134. {
  135.   struct Unit   *unit_ptr;
  136.  
  137.  
  138.   if ((unit_ptr = kr_getUnitPtr( UnitNo ) ) == NULL)
  139.     return( NULL );    /*  invalid unit #  */
  140.  
  141.   return( unit_ptr->unit_name );
  142. }
  143.  
  144.  
  145. /*****************************************************************************
  146.   FUNCTION : krui_setUnitName
  147.  
  148.   PURPOSE  : Sets the name of the unit <UnitNo>.
  149.              If the unit_name pointer is NULL, the unit's symbol will be deleted.
  150.              Function has no effect on the current unit.
  151.   NOTES    :
  152.  
  153.   RETURNS  : Returns error code if memory allocation fails, 0 otherwise.
  154.   UPDATE   : 
  155. ******************************************************************************/
  156. krui_err  krui_setUnitName(int unit_no, char *unit_name)
  157. {
  158.   struct Unit   *unit_ptr;
  159.   char    *str_ptr;
  160.  
  161.  
  162.   KernelErrorCode = KRERR_NO_ERROR;
  163.   if ((unit_ptr = kr_getUnitPtr( unit_no )) == NULL)
  164.     return( KernelErrorCode );
  165.  
  166.   if (unit_name == NULL)
  167.     {
  168.     krm_NTableReleaseSymbol( unit_ptr->unit_name, UNIT_SYM );
  169.     unit_ptr->unit_name = NULL;
  170.     return( KernelErrorCode );
  171.   }
  172.  
  173.   if (!kr_symbolCheck( unit_name ))  return( KernelErrorCode );
  174.  
  175.   if ( (str_ptr = krm_NTableInsertSymbol( unit_name, UNIT_SYM ) ) == NULL)
  176.     return( KernelErrorCode );
  177.  
  178.   unit_ptr->unit_name = str_ptr;
  179.  
  180.   return( KernelErrorCode );
  181. }
  182.  
  183. /*****************************************************************************
  184.   FUNCTION : krui_searchUnitName
  185.  
  186.   PURPOSE  : Searches for a unit with the given name
  187.   NOTES    :
  188.  
  189.   RETURNS  : Returns the first unit no. if a unit with the given name was found,
  190.              0 otherwise.
  191.   UPDATE   : 
  192. ******************************************************************************/
  193. int  krui_searchUnitName(char *unit_name)
  194. {
  195.   struct  NameTable  *n_ptr;
  196.  
  197.   if (NoOfUnits <= 0)  {
  198.     UICurrentNameSearchUnitNo = 0;
  199.     return( (int) KRERR_NO_UNITS );  /*  No Units defined  */
  200.   }
  201.  
  202.   if ((n_ptr = krm_NTableSymbolSearch( unit_name, UNIT_SYM )) == NULL)  {
  203.     UICurrentNameSearchUnitNo = 0;
  204.     return( 0 );
  205.   }
  206.  
  207.   UICurrentNameSearchUnitSymbolPtr = n_ptr->Entry.symbol;
  208.   UICurrentNameSearchUnitNo = kr_unitNameSearch( MinUnitNo, UICurrentNameSearchUnitSymbolPtr );
  209.  
  210.   return( UICurrentNameSearchUnitNo );
  211. }
  212.  
  213.  
  214. /*****************************************************************************
  215.   FUNCTION : krui_searchNextUnitName
  216.  
  217.   PURPOSE  : Searches for the next unit with the given name.
  218.   NOTES    : Call krui_searchUnitName( unit_name ) before calling krui_searchNextUnitName().
  219.              Returns error code if no units defined.
  220.  
  221.   RETURNS  : Returns the first unit no. if a unit with the given name was found,
  222.              0 otherwise.
  223.   UPDATE   : 
  224. ******************************************************************************/
  225. int  krui_searchNextUnitName(void)
  226. {
  227.   if (NoOfUnits <= 0)
  228.     {
  229.     UICurrentNameSearchUnitNo = 0;
  230.     return( KRERR_NO_UNITS );  /*  No Units defined  */
  231.   }
  232.  
  233.   if (UICurrentNameSearchUnitNo != 0)
  234.     {
  235.     UICurrentNameSearchUnitNo = kr_unitNameSearch( UICurrentNameSearchUnitNo + 1, UICurrentNameSearchUnitSymbolPtr );
  236.     return( UICurrentNameSearchUnitNo );
  237.   }
  238.   else
  239.     return( 0 );
  240. }
  241.  
  242. /*****************************************************************************
  243.   FUNCTION : krui_getUnitOutFuncName
  244.  
  245.   PURPOSE  : 
  246.   NOTES    :
  247.  
  248.   RETURNS  : Returns the output function name of the unit.
  249.   UPDATE   : 
  250. ******************************************************************************/
  251. char  *krui_getUnitOutFuncName(int UnitNo)
  252. {
  253.   struct Unit   *unit_ptr;
  254.   static char  out_func_name[FUNCTION_NAME_MAX_LEN];
  255.  
  256.   if ( (unit_ptr = kr_getUnitPtr( UnitNo ) ) == NULL)
  257.     return( NULL );    /*  invalid unit #  */
  258.  
  259.   strcpy( out_func_name, krf_getFuncName( (FunctionPtr) unit_ptr->out_func ));
  260.  
  261.   return( out_func_name );
  262. }
  263.  
  264. /*****************************************************************************
  265.   FUNCTION : krui_setUnitOutFunc(
  266.  
  267.   PURPOSE  : he unit's FType will be set to 0, i.e. the
  268.              unit's functionality type will be deleted.
  269.              Function has no effect on the current unit.
  270.   NOTES    :
  271.  
  272.   RETURNS  : returns 0, if the function is a valid output function,
  273.              error code otherwise.
  274.   UPDATE   : 
  275. ******************************************************************************/
  276. krui_err  krui_setUnitOutFunc(int unit_no, char *unitOutFuncName)
  277. {
  278.   struct Unit   *unit_ptr;
  279.   FunctionPtr func_ptr;
  280.  
  281. #ifdef MASPAR_KERNEL
  282.   MASPAR_FF1_VALIDATE_OP;
  283. #endif
  284.  
  285.   if ((unit_ptr = kr_getUnitPtr( unit_no )) == NULL)
  286.     return( KernelErrorCode );
  287.  
  288.   if ( !krf_funcSearch( unitOutFuncName, OUT_FUNC, &func_ptr ))
  289.     return( KernelErrorCode );
  290.  
  291.   unit_ptr->out_func = (OutFuncPtr) func_ptr;
  292.   unit_ptr->Ftype_entry = NULL;
  293.  
  294.   NetModified = TRUE;
  295.  
  296.   return( KRERR_NO_ERROR );
  297. }
  298.  
  299. /*****************************************************************************
  300.   FUNCTION : krui_getUnitActFuncName
  301.  
  302.   PURPOSE  : 
  303.   NOTES    :
  304.  
  305.   RETURNS  : Returns the activation function name of the unit.
  306.   UPDATE   : 
  307. ******************************************************************************/
  308. char  *krui_getUnitActFuncName(int UnitNo)
  309. {
  310.   struct Unit   *unit_ptr;
  311.   static char  act_func_name[FUNCTION_NAME_MAX_LEN];
  312.  
  313.  
  314.   if ( (unit_ptr = kr_getUnitPtr( UnitNo ) ) == NULL)
  315.     return( NULL );    /*  invalid unit #  */
  316.  
  317.   strcpy( act_func_name, krf_getFuncName( (FunctionPtr) unit_ptr->act_func ));
  318.  
  319.   return( act_func_name );
  320. }
  321.  
  322. /*****************************************************************************
  323.   FUNCTION : krui_setUnitActFunc
  324.  
  325.   PURPOSE  : The unit's FType will be set to 0, i.e. the
  326.              unit's functionality type will be deleted.
  327.              Function has no effect on the current unit. 
  328.   NOTES    :
  329.  
  330.   RETURNS  : returns 0, if the function is a valid activation function,
  331.              error code otherwise.
  332.   UPDATE   : 
  333. ******************************************************************************/
  334. krui_err  krui_setUnitActFunc(int unit_no, char *unitActFuncName)
  335. {
  336.   struct Unit   *unit_ptr;
  337.   FunctionPtr   act_func_ptr, act_deriv_func_ptr;
  338.  
  339. #ifdef MASPAR_KERNE
  340.   MASPAR_FF1_VALIDATE_OP;
  341. #endif
  342.  
  343.   if ((unit_ptr = kr_getUnitPtr( unit_no )) == NULL)
  344.     return( KernelErrorCode );
  345.   if ( !krf_funcSearch( unitActFuncName, ACT_FUNC, &act_func_ptr ))
  346.     return( KernelErrorCode );
  347.   /*  set the derivation function of the activation function  */ 
  348.   if ( !krf_funcSearch( unitActFuncName, ACT_DERIV_FUNC, &act_deriv_func_ptr ))
  349.     return( KernelErrorCode );
  350.  
  351.  
  352.   unit_ptr->act_func = (ActFuncPtr) act_func_ptr;
  353.   unit_ptr->act_deriv_func = (ActDerivFuncPtr) act_deriv_func_ptr;
  354.   unit_ptr->Ftype_entry = NULL;
  355.  
  356.   NetModified = TRUE;
  357.  
  358.   return( KRERR_NO_ERROR );
  359. }
  360.  
  361. /*****************************************************************************
  362.   FUNCTION : krui_getUnitFTypeName
  363.  
  364.   PURPOSE  : 
  365.   NOTES    : Function has no effect on the current unit.
  366.  
  367.   RETURNS  : Returns the functionality type name of the unit.
  368.              Function has no effect on the current unit.
  369.              Returns NULL if unit has no FType.
  370.   UPDATE   : 
  371. ******************************************************************************/
  372. char  *krui_getUnitFTypeName(int UnitNo)
  373. {
  374.   struct FtypeUnitStruct    *Ftype_entry;
  375.   struct Unit   *unit_ptr;
  376.  
  377.  
  378.   if ( (unit_ptr = kr_getUnitPtr( UnitNo ) ) == NULL)
  379.     return( NULL );    /*  invalid unit #  */
  380.  
  381.   if ( (Ftype_entry = unit_ptr->Ftype_entry) == NULL)
  382.     return( NULL );
  383.  
  384.   return( Ftype_entry->Ftype_symbol->Entry.symbol );
  385. }
  386.  
  387.  
  388.  
  389.  
  390. /*****************************************************************************
  391.   FUNCTION : krui_getUnitActivation
  392.  
  393.   PURPOSE  : 
  394.   NOTES    : Function has no effect on the current unit.
  395.  
  396.   RETURNS  : Returns the activation value of the unit.
  397.   UPDATE   : 
  398. ******************************************************************************/
  399. FlintType  krui_getUnitActivation(int UnitNo)
  400. {
  401.   if KERNEL_STANDARD {
  402.     return( kr_getUnitValues( UnitNo, SEL_UNIT_ACT ) );
  403.   }
  404.   else  {
  405.  
  406. #ifdef MASPAR_KERNEL
  407.  
  408.     return( krff_getUnitValues( UnitNo, SEL_UNIT_ACT ) );
  409.  
  410. #else
  411.  
  412.     KernelErrorCode = KRERR_NO_MASPAR_KERNEL;
  413.     return( 0.0 );
  414.  
  415. #endif
  416.   }
  417. }
  418.  
  419.  
  420. /*****************************************************************************
  421.   FUNCTION : krui_setUnitActivation
  422.  
  423.   PURPOSE  : Sets the activation value of the unit.
  424.              Function has no effect on the current unit.
  425.   NOTES    :
  426.  
  427.   RETURNS  :
  428.   UPDATE   : 
  429. ******************************************************************************/
  430. krui_err  krui_setUnitActivation(int UnitNo, FlintTypeParam unit_activation)
  431. {
  432.   krui_err err = KRERR_NO_ERROR;
  433.  
  434.   if KERNEL_STANDARD  {
  435.     err = kr_setUnitValues( UnitNo, SEL_UNIT_ACT, unit_activation );
  436.   }
  437.   else  {
  438.  
  439. #ifdef MASPAR_KERNEL
  440.  
  441.     (void) krff_setUnitValues( UnitNo, SEL_UNIT_ACT, unit_activation );
  442.  
  443. #else
  444.  
  445.     KernelErrorCode = KRERR_NO_MASPAR_KERNEL;
  446.  
  447. #endif
  448.   }
  449.   return(err);
  450. }
  451.  
  452. /*****************************************************************************
  453.   FUNCTION : krui_getUnitInitialActivation
  454.  
  455.   PURPOSE  : 
  456.   NOTES    : Function has no effect on the current unit.
  457.  
  458.   RETURNS  : Returns the initial activation value of the unit.
  459.   UPDATE   : 
  460. ******************************************************************************/
  461. FlintType  krui_getUnitInitialActivation(int UnitNo)
  462. {
  463.   if KERNEL_STANDARD
  464.     return( kr_getUnitValues( UnitNo, SEL_UNIT_IACT ) );
  465.   else  {
  466.  
  467. #ifdef MASPAR_KERNEL
  468.  
  469.     return( krff_getUnitValues( UnitNo, SEL_UNIT_IACT ) );
  470.  
  471. #else
  472.  
  473.     KernelErrorCode = KRERR_NO_MASPAR_KERNEL;
  474.     return( 0.0 );
  475.  
  476. #endif
  477.   }
  478. }
  479.  
  480. /*****************************************************************************
  481.   FUNCTION : krui_setUnitInitialActivation
  482.  
  483.   PURPOSE  : Sets the initial activation value of the unit.
  484.              Function has no effect on the current unit.
  485.   NOTES    :
  486.  
  487.   RETURNS  :
  488.   UPDATE   : 
  489. ******************************************************************************/
  490. void  krui_setUnitInitialActivation(int UnitNo, FlintTypeParam unit_i_activation)
  491. {
  492.   if KERNEL_STANDARD
  493.     kr_setUnitValues( UnitNo, SEL_UNIT_IACT, unit_i_activation );
  494.   else  {
  495.  
  496. #ifdef MASPAR_KERNEL
  497.  
  498.     krff_setUnitValues( UnitNo, SEL_UNIT_IACT, unit_i_activation );
  499.  
  500. #else
  501.  
  502.     KernelErrorCode = KRERR_NO_MASPAR_KERNEL;
  503.  
  504. #endif
  505.   }
  506. }
  507.  
  508.  
  509. /*****************************************************************************
  510.   FUNCTION : krui_getUnitOutput
  511.  
  512.   PURPOSE  : 
  513.   NOTES    : Function has no effect on the current unit.
  514.  
  515.   RETURNS  : Returns the output value of the unit.
  516.   UPDATE   : 
  517. ******************************************************************************/
  518. FlintType  krui_getUnitOutput(int UnitNo)
  519. {
  520.   if KERNEL_STANDARD
  521.     return( kr_getUnitValues( UnitNo, SEL_UNIT_OUT ) );
  522.   else  {
  523.  
  524. #ifdef MASPAR_KERNEL
  525.  
  526.     return( krff_getUnitValues( UnitNo, SEL_UNIT_OUT ) );
  527.  
  528. #else
  529.  
  530.     KernelErrorCode = KRERR_NO_MASPAR_KERNEL;
  531.     return( 0.0 );
  532.  
  533. #endif
  534.   }
  535. }
  536.  
  537. /*****************************************************************************
  538.   FUNCTION : krui_setUnitOutput
  539.  
  540.   PURPOSE  : Sets the output value of the unit.
  541.              Function has no effect on the current unit.
  542.   NOTES    :
  543.  
  544.   RETURNS  :
  545.   UPDATE   : 
  546. ******************************************************************************/
  547. krui_err  krui_setUnitOutput(int unit_no, FlintTypeParam unit_output)
  548. {
  549.   if KERNEL_STANDARD  {
  550.     kr_setUnitValues( unit_no, SEL_UNIT_OUT, unit_output );
  551.   }
  552.   else  {
  553.  
  554. #ifdef MASPAR_KERNEL
  555.  
  556.     krff_setUnitValues( unit_no, SEL_UNIT_OUT, unit_output );
  557.  
  558. #else
  559.  
  560.     KernelErrorCode = KRERR_NO_MASPAR_KERNEL;
  561.  
  562. #endif
  563.   }
  564.  
  565.   return( KernelErrorCode );
  566. }
  567.  
  568. /*****************************************************************************
  569.   FUNCTION : krui_getUnitBias
  570.  
  571.   PURPOSE  : 
  572.   NOTES    : Function has no effect on the current unit.
  573.  
  574.   RETURNS  : Returns the bias value of the unit.
  575.   UPDATE   : 
  576. ******************************************************************************/
  577. FlintType  krui_getUnitBias(int UnitNo)
  578. {
  579.   if KERNEL_STANDARD  {
  580.     return( kr_getUnitValues( UnitNo, SEL_UNIT_BIAS ) );
  581.   }
  582.   else  {
  583.  
  584. #ifdef MASPAR_KERNEL
  585.  
  586.     return( krff_getUnitValues( UnitNo, SEL_UNIT_BIAS ) );
  587.  
  588. #else
  589.  
  590.     KernelErrorCode = KRERR_NO_MASPAR_KERNEL;
  591.     return( 0.0 );
  592.  
  593. #endif
  594.   }
  595. }
  596. /*****************************************************************************
  597.   FUNCTION : krui_setUnitBias
  598.  
  599.   PURPOSE  : Sets the bias value of the unit.
  600.              Function has no effect on the current unit.
  601.   NOTES    :
  602.  
  603.   RETURNS  :
  604.   UPDATE   : 
  605. ******************************************************************************/
  606. void  krui_setUnitBias(int UnitNo, FlintTypeParam unit_bias)
  607. {
  608.   if KERNEL_STANDARD  {
  609.     kr_setUnitValues( UnitNo, SEL_UNIT_BIAS, unit_bias );
  610.   }
  611.   else  {
  612.  
  613. #ifdef MASPAR_KERNEL
  614.  
  615.     krff_setUnitValues( UnitNo, SEL_UNIT_BIAS, unit_bias );
  616.  
  617. #else
  618.  
  619.     KernelErrorCode = KRERR_NO_MASPAR_KERNEL;
  620.  
  621. #endif
  622.   }
  623. }
  624.  
  625. /****************************************************************************
  626.   FUNCTION : krui_getUnitValueA
  627.   PURPOSE  : 
  628.   NOTES    : Function has no effect on the current unit.
  629.   
  630.   RETURNS  : Returns Value A of the unit.
  631.   UPDATE   : 
  632. ****************************************************************************/
  633. FlintType  krui_getUnitValueA(int UnitNo)
  634. {
  635.   if KERNEL_STANDARD  {
  636.     return( kr_getUnitValues( UnitNo, SEL_UNIT_VALA ) );
  637.   }
  638.   else  {
  639.   
  640. #ifdef MASPAR_KERNEL
  641.  
  642.     return( krff_getUnitValues( UnitNo, SEL_UNIT_VALA ) );
  643.  
  644. #else
  645.  
  646.     KernelErrorCode = KRERR_NO_MASPAR_KERNEL;
  647.     return( 0.0 );
  648.  
  649. #endif
  650.   }
  651. }
  652.  
  653. /******************************************************************************
  654.   FUNCTION : krui_setUnitValueA
  655.  
  656.   PURPOSE  : Sets value a of the unit.
  657.   NOTES    : Function has no effect on the current unit.
  658.  
  659.  
  660.   RETURNS  : 
  661.   UPDATE   : 
  662. *****************************************************************************/
  663. void  krui_setUnitValueA(int UnitNo, FlintTypeParam unit_valueA)
  664. {
  665.   if KERNEL_STANDARD  {
  666.     kr_setUnitValues( UnitNo, SEL_UNIT_VALA, unit_valueA );
  667.   }
  668.   else  {
  669.  
  670. #ifdef MASPAR_KERNEL
  671.  
  672.     krff_setUnitValues( UnitNo, SEL_UNIT_VALA, unit_valueA );
  673.  
  674. #else
  675.  
  676.     KernelErrorCode = KRERR_NO_MASPAR_KERNEL;
  677.  
  678. #endif
  679.   }
  680. }
  681.  
  682. /*****************************************************************************
  683.   FUNCTION : krui_getUnitSubnetNo
  684.  
  685.   PURPOSE  : 
  686.   NOTES    : Function has no effect on the current unit.
  687.              The range of the subnet no. is -32736...+32735
  688.  
  689.   RETURNS  : Returns the subnet number of the unit.
  690.   UPDATE   : 
  691. ******************************************************************************/
  692. int  krui_getUnitSubnetNo(int UnitNo)
  693. {
  694.   struct Unit   *unit_ptr;
  695.  
  696.   if ( (unit_ptr = kr_getUnitPtr( UnitNo ) ) == NULL)
  697.     return( 0 );    /*  invalid unit #  */
  698.  
  699.   return( (int) unit_ptr->subnet_no );
  700. }
  701. /*****************************************************************************
  702.   FUNCTION : 
  703.  
  704.   PURPOSE  : Sets the subnet number of the unit.
  705.              Function has no effect on the current unit.
  706.   NOTES    : The range of the subnet no. is -32736...+32735
  707.  
  708.   RETURNS  :
  709.   UPDATE   : 
  710. ******************************************************************************/
  711. void  krui_setUnitSubnetNo(int UnitNo, int subnet_no)
  712. {
  713.   struct Unit   *unit_ptr;
  714.  
  715.   if ( (unit_ptr = kr_getUnitPtr( UnitNo ) ) == NULL)
  716.     return;    /*  invalid unit #  */
  717.  
  718.   NetModified = TRUE;
  719.  
  720.   unit_ptr->subnet_no = (short) subnet_no;
  721. }
  722.  
  723. /*****************************************************************************
  724.   FUNCTION : krui_getUnitLayerNo
  725.  
  726.   PURPOSE  : 
  727.   NOTES    : Function has no effect on the current unit.
  728.              The range of the layer no. is -32736...+32735
  729.  
  730.   RETURNS  : Returns the layer number of the unit.
  731.   UPDATE   : 
  732. ******************************************************************************/
  733. unsigned short    krui_getUnitLayerNo(int UnitNo)
  734. {
  735.   struct Unit   *unit_ptr;
  736.  
  737.   if ( (unit_ptr = kr_getUnitPtr( UnitNo ) ) == NULL)
  738.     return( 0 );    /*  invalid unit #  */
  739.  
  740.   return( (unsigned short) unit_ptr->layer_no );
  741. }
  742. /*****************************************************************************
  743.   FUNCTION : krui_setUnitLayerNo
  744.  
  745.   PURPOSE  : Sets the layer number of the unit.
  746.   NOTES    : Function has no effect on the current unit.
  747.              The range of the layer no. is -32736...+32735
  748.   RETURNS  :
  749.   UPDATE   : 
  750. ******************************************************************************/
  751. void    krui_setUnitLayerNo(int UnitNo, int layer_no)
  752. {
  753.   struct Unit   *unit_ptr;
  754.  
  755.   if ( (unit_ptr = kr_getUnitPtr( UnitNo ) ) == NULL)
  756.     return;    /*  invalid unit #  */
  757.  
  758.   NetModified = TRUE;
  759.  
  760.   unit_ptr->layer_no = (unsigned short) layer_no;
  761. }
  762.  
  763. /*****************************************************************************
  764.   FUNCTION : krui_getUnitPosition
  765.  
  766.   PURPOSE  : 
  767.   NOTES    : Function has no effect on the current unit.
  768.  
  769.   RETURNS  : Returns the position of the unit.
  770.   UPDATE   : 
  771. ******************************************************************************/
  772. void    krui_getUnitPosition(int UnitNo, struct PosType *position)
  773. {
  774.   struct Unit   *unit_ptr;
  775.  
  776.   if ( (unit_ptr = kr_getUnitPtr( UnitNo ) ) == NULL)
  777.     return;    /*  invalid unit #  */
  778.  
  779.   position->x = unit_ptr->unit_pos.x;
  780.   position->y = unit_ptr->unit_pos.y;
  781. #ifdef KERNEL3D
  782.   position->z = unit_ptr->unit_pos.z;
  783. #endif
  784. }
  785. /*****************************************************************************
  786.   FUNCTION : krui_setUnitPosition
  787.  
  788.   PURPOSE  : Sets the position of the unit.
  789.   NOTES    : Function has no effect on the current unit
  790.  
  791.   RETURNS  : 
  792.   UPDATE   : 
  793. ******************************************************************************/
  794. void    krui_setUnitPosition(int UnitNo, struct PosType *position)
  795. {
  796.   struct Unit   *unit_ptr;
  797.  
  798.   if ( (unit_ptr = kr_getUnitPtr( UnitNo ) ) == NULL)
  799.     return;    /*  invalid unit #  */
  800.  
  801.   unit_ptr->unit_pos.x = position->x;
  802.   unit_ptr->unit_pos.y = position->y;
  803. #ifdef KERNEL3D
  804.   unit_ptr->unit_pos.z = position->z;
  805. #endif
  806. }
  807.  
  808. /*****************************************************************************
  809.   FUNCTION : krui_getUnitNoAtPosition
  810.  
  811.   PURPOSE  : 
  812.   NOTES    : Function has no effect on the current unit.
  813.              This function is slow because it uses linear search to
  814.              find the unit with the given position.
  815.   REMARK   : getUnitNoAtPosition is for downward compatibility only.
  816.              Do not use this function in future applications.
  817.  
  818.   RETURNS  : Returns the unit no. at the given position and subnet number or 0, if
  819.              no unit exists at this position
  820.   UPDATE   : 
  821. ******************************************************************************/
  822. int   krui_getUnitNoAtPosition(struct PosType *position, int subnet_no)
  823. {
  824.   register int       i;
  825.   register short     x, y, net_no;
  826.   struct Unit     *unit_ptr;
  827.  
  828.  
  829.   x = position->x;
  830.   y = position->y;
  831.  
  832.   net_no = (short) subnet_no;
  833.  
  834.   for (i = 1, unit_ptr = unit_array + 1;
  835.        i <= MaxUnitNo;
  836.        i++, unit_ptr++)
  837.     {
  838.     if ( UNIT_IN_USE( unit_ptr ) &&
  839.          (unit_ptr->subnet_no == net_no) &&
  840.          (unit_ptr->unit_pos.x == x) && (unit_ptr->unit_pos.y == y) )
  841.  
  842.       return( i );
  843.     }
  844.  
  845.   return( 0 );
  846. }
  847. /*****************************************************************************
  848.   FUNCTION : krui_getUnitNoNearPosition
  849.  
  850.   PURPOSE  : 
  851.   NOTES    : Function has no effect on the current unit.
  852.              This function is slow because it uses linear search to
  853.              find the unit with the given position.
  854.  
  855.   RETURNS  : Returns the unit no. near the given position and the specified
  856.              subnet no or 0, if no unit exists at this position.
  857.   UPDATE   : 
  858. ******************************************************************************/
  859. int  krui_getUnitNoNearPosition(struct PosType *position, int subnet_no, int range, int gridWidth)
  860. {
  861.   register int       i, devit, width;
  862.   register short     x, y, net_no;
  863.   struct Unit        *unit_ptr;
  864.  
  865.  
  866.   x = position->x;
  867.   y = position->y;
  868.   net_no = (short) subnet_no;
  869.   devit = range;
  870.   width = gridWidth;
  871.  
  872.   for (i = 1, unit_ptr = unit_array + 1; i <= MaxUnitNo;
  873.        i++, unit_ptr++)
  874.     {
  875.     if ( UNIT_IN_USE( unit_ptr ) &&
  876.          (unit_ptr->subnet_no == net_no) &&
  877.          (abs( unit_ptr->unit_pos.x - x) * width <= devit) && 
  878.          (abs( unit_ptr->unit_pos.y - y) * width <= devit) )
  879.       return( i );
  880.     }
  881.  
  882.   return( 0 );
  883. }
  884.  
  885.  
  886. /*****************************************************************************
  887.   FUNCTION : krui_getUnitTType
  888.  
  889.   PURPOSE  : 
  890.   NOTES    : Function has no effect on the current unit.
  891.  
  892.   RETURNS  : Returns the topologic type, i.e. input, output, hidden
  893.   UPDATE   : 
  894. ******************************************************************************/
  895. int  krui_getUnitTType(int unit_no)
  896. {
  897.   struct Unit   *unit_ptr;
  898.  
  899.   if ((unit_ptr = kr_getUnitPtr( unit_no )) == NULL)
  900.     return( KernelErrorCode );
  901.  
  902.   return( kr_flags2TType( (int) unit_ptr->flags & UFLAG_TTYP_PAT ) );
  903. }
  904.  
  905. /*****************************************************************************
  906.   FUNCTION : krui_setUnitTType
  907.  
  908.   PURPOSE  : Sets the topologic type of the unit.
  909.              Function has no effect on the current unit.
  910.   NOTES    : 
  911.  
  912.   RETURNS  : Returns error code if topologic type or unit number is invalid.
  913.   UPDATE   : 
  914. ******************************************************************************/
  915. krui_err  krui_setUnitTType(int unit_no, int UnitTType)
  916. {
  917. #ifdef MASPAR_KERNEL
  918.   MASPAR_FF1_VALIDATE_OP;
  919. #endif
  920.  
  921.   return( kr_unitSetTType( unit_no, UnitTType ) );
  922. }
  923.  
  924. /*****************************************************************************
  925.   FUNCTION : krui_freezeUnit
  926.  
  927.   PURPOSE  : Freezes the output of a unit, i.e. the unit is disabled.
  928.              Function has no effect on the current unit.
  929.   NOTES    : 
  930.  
  931.   RETURNS  : 
  932.   UPDATE   : 
  933. ******************************************************************************/
  934. krui_err  krui_freezeUnit(int unit_no)
  935. {
  936.   struct Unit   *unit_ptr;
  937.  
  938. #ifdef MASPAR_KERNEL
  939.   MASPAR_FF1_VALIDATE_OP;
  940. #endif
  941.  
  942.   if ((unit_ptr = kr_getUnitPtr( unit_no )) == NULL)
  943.     return( KernelErrorCode );
  944.  
  945.   unit_ptr->flags &= (~UFLAG_ENABLED);
  946.   return( KRERR_NO_ERROR );
  947. }
  948.  
  949. /*****************************************************************************
  950.   FUNCTION : krui_unfreezeUnit
  951.  
  952.   PURPOSE  : Enables a previosly freezed unit.
  953.              Function has no effect on the current unit.
  954.   NOTES    : 
  955.  
  956.   RETURNS  : 
  957.   UPDATE   : 
  958. ******************************************************************************/
  959. krui_err  krui_unfreezeUnit(int unit_no)
  960. {
  961.   struct Unit   *unit_ptr;
  962.  
  963. #ifdef MASPAR_KERNEL
  964.   MASPAR_FF1_VALIDATE_OP;
  965. #endif
  966.  
  967.   if ((unit_ptr = kr_getUnitPtr( unit_no )) == NULL)
  968.     return( KernelErrorCode );
  969.  
  970.   unit_ptr->flags |= UFLAG_ENABLED;
  971.   return( KRERR_NO_ERROR );
  972. }
  973.  
  974. /*****************************************************************************
  975.   FUNCTION : krui_isUnitFrozen
  976.  
  977.   PURPOSE  : 
  978.   NOTES    : 
  979.  
  980.   RETURNS  : Returns true, if unit is frozen
  981.   UPDATE   : 
  982. ******************************************************************************/
  983. bool  krui_isUnitFrozen(int unit_no)
  984. {
  985.   struct Unit   *unit_ptr;
  986.  
  987.   if ((unit_ptr = kr_getUnitPtr( unit_no )) == NULL)
  988.     return( KernelErrorCode );
  989.  
  990.   return( (unit_ptr->flags & UFLAG_ENABLED) == 0 );
  991. }
  992.  
  993.  
  994. /*****************************************************************************
  995.   FUNCTION : 
  996.  
  997.   PURPOSE  : 
  998.   NOTES    : Function has no effect on the current unit. 
  999.  
  1000.   RETURNS  : Returns the input type of the unit:
  1001.              NO_INPUTS    : if the unit has not inputs (at least not now)
  1002.              SITES        : if the unit has one or more sites (and no direct input links !)
  1003.              DIRECT_LINKS : if the unit has direct input links (and no sites !)
  1004.  
  1005.   UPDATE   : 
  1006. ******************************************************************************/
  1007. int  krui_getUnitInputType(int unit_no)
  1008. {
  1009.   struct Unit  *unit_ptr;
  1010.  
  1011.   if ((unit_ptr = kr_getUnitPtr( unit_no )) == NULL)
  1012.     return( KernelErrorCode );
  1013.  
  1014.   switch ((int) unit_ptr->flags & UFLAG_INPUT_PAT)
  1015.     {
  1016.     case UFLAG_NO_INP :  return( NO_INPUTS    );
  1017.     case UFLAG_SITES  :  return( SITES        );
  1018.     case UFLAG_DLINKS :  return( DIRECT_LINKS );
  1019.  
  1020.     default :  return( NO_INPUTS );
  1021.   }
  1022. }
  1023.  
  1024.  
  1025.  
  1026. /*****************************************************************************
  1027.   FUNCTION : krui_createDefaultUnit
  1028.  
  1029.   PURPOSE  :  creates a unit with default properties:
  1030.               1. default activation and output functions
  1031.               2. default activation and bias
  1032.               3. default position, subnet and layer number
  1033.               4. no functionality type
  1034.               5. no sites
  1035.               6. no inputs and outputs
  1036.               7. no unit_name
  1037.   NOTES    :  See file "kr_def.h" for more details about default presettings.
  1038.               Function has no effect on the current unit.
  1039.  
  1040.   RETURNS  :  Returns an (negative) error code, if memory allocation fails or
  1041.               invalid functions occured. Returns (positive) unit number otherwise.
  1042.   UPDATE   : 
  1043. ******************************************************************************/
  1044. int  krui_createDefaultUnit(void)
  1045. {
  1046. #ifdef MASPAR_KERNEL
  1047.   MASPAR_FF1_VALIDATE_OP;
  1048. #endif
  1049.  
  1050.   NetModified = TRUE;
  1051.   return( kr_makeDefaultUnit() );
  1052. }
  1053.  
  1054. /*****************************************************************************
  1055.   FUNCTION : krui_createUnit
  1056.  
  1057.   PURPOSE  : Creates a user defined unit.
  1058.              Returns an (negative) error code, if memory allocation fails or
  1059.              invalid functions occured. Returns (positive) unit number otherwise.
  1060.              Function has no effect on the current unit.
  1061.  
  1062.              Unit has additional default settings:
  1063.              1. default position, subnet and layer number
  1064.              2. no functionality type
  1065.              3. no sites
  1066.              4. no inputs and outputs
  1067.  
  1068.   NOTES    : 
  1069.  
  1070.   RETURNS  : 
  1071.   UPDATE   : 
  1072. ******************************************************************************/
  1073. int  krui_createUnit(char *unit_name, char *out_func_name, char *act_func_name, FlintTypeParam i_act, FlintTypeParam bias)
  1074. {
  1075. #ifdef MASPAR_KERNEL
  1076.   MASPAR_FF1_VALIDATE_OP;
  1077. #endif
  1078.  
  1079.   return( kr_createUnit( unit_name, out_func_name, act_func_name, i_act, bias) );
  1080. }
  1081.  
  1082.  
  1083.  
  1084. /*****************************************************************************
  1085.                  UNDOCUMENTED FUNCTION SINCE SNNS VERSION 3.0
  1086.                    !!!! DO NOT USE THIS FUNCTION ANY MORE  !!!
  1087.                    !!!! USE: krui_deleteUnitList() INSTEAD !!!
  1088.  
  1089.   FUNCTION : krui_deleteUnit
  1090.  
  1091.   PURPOSE  : Deletes a unit from network. Removes all links to other units. 
  1092.   NOTES    : !!!! DO NOT USE THIS FUNCTION ANY MORE !!!
  1093.              !!!! USE: krui_deleteUnitList() INSTEAD !!!
  1094.  
  1095.   RETURNS  : Returns error code if unit doesn't exist. 
  1096.   UPDATE   : 
  1097. ******************************************************************************/
  1098. krui_err  krui_deleteUnit(int unit_no)
  1099. {
  1100.   struct  Unit      *unit_ptr;
  1101.  
  1102. #ifdef MASPAR_KERNEL
  1103.   MASPAR_FF1_VALIDATE_OP;
  1104. #endif
  1105.  
  1106.   if ((unit_ptr = kr_getUnitPtr( unit_no )) == NULL)
  1107.     return( KernelErrorCode );
  1108.  
  1109.   (void) kr_removeUnit( unit_ptr );
  1110.   NetModified = TRUE;
  1111.   return( KernelErrorCode );
  1112. }
  1113.  
  1114.  
  1115. /*****************************************************************************
  1116.   FUNCTION : krui_deleteUnitList
  1117.  
  1118.   PURPOSE  : Deletes 'no_of_units' from the network. The numbers of the
  1119.              units that have to be deleted are listed up in an array
  1120.          of integers beginning with index 0. 
  1121.              This array is passed to parameter 'unit_list'.
  1122.              Removes all links to and from these units. 
  1123.              
  1124.   NOTES    : Always use this function instead of krui_deleteUnit()
  1125.  
  1126.   RETURNS  : Returns error code if unit doesn't exist. 
  1127.   UPDATE   : 
  1128. ******************************************************************************/
  1129. krui_err  krui_deleteUnitList(int no_of_units, int unit_list[])
  1130. {
  1131.   struct  Unit      *unit_ptr;
  1132.   int               i;
  1133.  
  1134. #ifdef MASPAR_KERNEL
  1135.   MASPAR_FF1_VALIDATE_OP;
  1136. #endif
  1137.  
  1138.   for (i=0; i < no_of_units; i++) {
  1139.      if ((unit_ptr = kr_getUnitPtr( unit_list[i] )) == NULL) {
  1140.        return( KernelErrorCode );
  1141.      } /*if*/
  1142.  
  1143.      (void) kr_removeUnit( unit_ptr );
  1144.   } /*for*/
  1145.  
  1146.   /* Now perform Garbage Collection */
  1147.   kr_forceUnitGC();
  1148.  
  1149.   NetModified = TRUE;
  1150.   return( KernelErrorCode );
  1151. }
  1152.  
  1153. /*****************************************************************************
  1154.   FUNCTION : krui_createFTypeUnit
  1155.  
  1156.   PURPOSE  : creates a unit with FType properties, but:
  1157.              1. no inputs and outputs
  1158.              2. default position, subnet and layer
  1159.  
  1160.   NOTES    : Function has no effect on the current unit. 
  1161.  
  1162.   RETURNS  : Returns the unit number or (negative) error code if memory allocation
  1163.              fails or functionality type isn't defined.
  1164.   UPDATE   : 
  1165. ******************************************************************************/
  1166. int  krui_createFTypeUnit(char *Ftype_symbol)
  1167. {
  1168.   int     unit_no;
  1169.  
  1170. #ifdef MASPAR_KERNEL
  1171.   MASPAR_FF1_VALIDATE_OP;
  1172. #endif
  1173.  
  1174.   unit_no = kr_makeFtypeUnit( Ftype_symbol );
  1175.   if (KernelErrorCode != KRERR_NO_ERROR)
  1176.     return( KernelErrorCode );
  1177.  
  1178.   NetModified = TRUE;
  1179.   return( unit_no );
  1180. }
  1181.  
  1182. /*****************************************************************************
  1183.   FUNCTION : krui_setUnitFType
  1184.  
  1185.   PURPOSE  : Changes the properties of unit <UnitNo> to FType properties.
  1186.              Changes: activation/output function and site name/functions.
  1187.   NOTES    : Function has no effect on the current unit.
  1188.  
  1189.   RETURNS  : Returns an error code if
  1190.              - FType name doesn't exist or
  1191.              - unit doesn't exist or
  1192.              - memory allocation fails
  1193.              otherwise 0.
  1194.         
  1195.   UPDATE   : 
  1196. ******************************************************************************/
  1197. krui_err  krui_setUnitFType(int unit_no, char *Ftype_symbol)
  1198. {
  1199.   struct  Unit      *unit_ptr;
  1200.   struct  FtypeUnitStruct   *ftype_ptr;
  1201.  
  1202. #ifdef MASPAR_KERNEL
  1203.   MASPAR_FF1_VALIDATE_OP;
  1204. #endif
  1205.  
  1206.   if ((unit_ptr = kr_getUnitPtr( unit_no )) == NULL)
  1207.     return( KernelErrorCode );
  1208.   if (!kr_symbolCheck( Ftype_symbol ))
  1209.     return( KernelErrorCode );
  1210.  
  1211.   if ( (ftype_ptr = krm_FtypeSymbolSearch( Ftype_symbol ) ) == NULL)
  1212.     {  /*  Ftype name isn't defined    */
  1213.     KernelErrorCode = KRERR_FTYPE_SYMBOL;
  1214.     return( KernelErrorCode );
  1215.   }
  1216.  
  1217.   NetModified = TRUE;
  1218.   kr_changeFtypeUnit( unit_ptr, ftype_ptr );
  1219.   return( KRERR_NO_ERROR );
  1220. }
  1221.  
  1222.  
  1223. /*****************************************************************************
  1224.   FUNCTION : krui_copyUnit
  1225.  
  1226.   PURPOSE  : Copy a given unit, according to the copy mode
  1227.              1. copy unit (with it sites, if available) and input/output links
  1228.              2. copy unit (with it sites, if available) and input links
  1229.              3. copy unit (with it sites, if available) and output links
  1230.              4. copy unit (with it sites, if available) but no input/output links
  1231.   NOTES    : Function has no effect on the current unit.
  1232.              Copying of output links is slow.
  1233.              If return code < 0, an error occured.
  1234.  
  1235.   RETURNS  : Returns the unit number of the new unit or error message < 0 , if errors occured.
  1236.   UPDATE   : 
  1237. ******************************************************************************/
  1238. int   krui_copyUnit(int unit_no, int copy_mode)
  1239. {
  1240.   int   new_unit_no;
  1241.  
  1242. #ifdef MASPAR_KERNEL
  1243.   MASPAR_FF1_VALIDATE_OP;
  1244. #endif
  1245.  
  1246.   new_unit_no = kr_copyUnit( copy_mode, unit_no );
  1247.   if (KernelErrorCode != KRERR_NO_ERROR)
  1248.     return( KernelErrorCode );
  1249.  
  1250.   return( new_unit_no );
  1251. }
  1252.  
  1253.  
  1254.  
  1255. /*#################################################
  1256.  
  1257. GROUP: Functions for manipulation of the Unit-Functionality-List
  1258. REMEMBER: The Unit-Functionality-List stores:
  1259.             1. unit activation and output functions
  1260.             2. if sites:  3. all site functions
  1261.                           4. all site names
  1262.  
  1263.  
  1264. #################################################*/
  1265. /*****************************************************************************
  1266.   FUNCTION : krui_setFirstFTypeEntry
  1267.  
  1268.   PURPOSE  : Initializes the first FType entry.
  1269.   NOTES    : 
  1270.  
  1271.   RETURNS  : Returns true, if an entry is available
  1272.   UPDATE   : 
  1273. ******************************************************************************/
  1274. bool  krui_setFirstFTypeEntry(void)
  1275. {
  1276.   UICurrentFtypeEntry = krm_getFtypeFirstEntry();
  1277.   UICurrentFtypeSite = NULL;
  1278.   return( UICurrentFtypeEntry != NULL );
  1279. }
  1280. /*****************************************************************************
  1281.   FUNCTION : krui_setNextFTypeEntry
  1282.  
  1283.   PURPOSE  : Initializes the next FType entry.
  1284.   NOTES    : 
  1285.  
  1286.   RETURNS  : Returns true, if an entry is available
  1287.   UPDATE   : 
  1288. ******************************************************************************/
  1289. bool  krui_setNextFTypeEntry(void)
  1290. {
  1291.   struct  FtypeUnitStruct   *ftype_ptr;
  1292.  
  1293.  
  1294.   UICurrentFtypeSite = NULL;
  1295.   if ( (ftype_ptr = krm_getFtypeNextEntry() ) != NULL)
  1296.     {
  1297.     UICurrentFtypeEntry = ftype_ptr;
  1298.     return( TRUE );
  1299.     }
  1300.  
  1301.   return( FALSE );
  1302. }
  1303.  
  1304. /*****************************************************************************
  1305.   FUNCTION : krui_setFTypeEntry
  1306.  
  1307.   PURPOSE  : Initializes the FType entry with the given name.
  1308.   NOTES    : 
  1309.  
  1310.   RETURNS  : Returns true, if an entry with this name is available.
  1311.   UPDATE   : 
  1312. ******************************************************************************/
  1313. bool  krui_setFTypeEntry(char *Ftype_symbol)
  1314. {
  1315.   struct  FtypeUnitStruct   *ftype_ptr;
  1316.  
  1317.  
  1318.   if ( (ftype_ptr = krm_FtypeSymbolSearch( Ftype_symbol ) ) != NULL)
  1319.     {
  1320.     UICurrentFtypeEntry = ftype_ptr;
  1321.     return( TRUE );
  1322.     }
  1323.  
  1324.   return( FALSE );
  1325. }
  1326.  
  1327. /*****************************************************************************
  1328.   FUNCTION : krui_getFTypeName
  1329.  
  1330.   PURPOSE  : 
  1331.   NOTES    : The FType name is definite and will never be
  1332.              a NULL pointer.
  1333.  
  1334.   RETURNS  : Returns the name of the current FType entry.
  1335.   UPDATE   : 
  1336. ******************************************************************************/
  1337. char  *krui_getFTypeName(void)
  1338. {
  1339.   if (UICurrentFtypeEntry == NULL)
  1340.     return( NULL );
  1341.  
  1342.   return( UICurrentFtypeEntry->Ftype_symbol->Entry.symbol );
  1343. }
  1344.  
  1345. /*****************************************************************************
  1346.   FUNCTION : krui_setFTypeName
  1347.  
  1348.   PURPOSE  : Sets the name of the current FType entry. 
  1349.   NOTES    : The new FType name have to be definite and must not be
  1350.              a NULL pointer.
  1351.  
  1352.   RETURNS  : Returns error code if memory allocation fails or Ftype name
  1353.              isn't definite, 0 otherwise.
  1354.   UPDATE   : 
  1355. ******************************************************************************/
  1356. krui_err  krui_setFTypeName(char *Ftype_symbol)
  1357. {
  1358.   struct NameTable    *NTable_ptr;
  1359.  
  1360.  
  1361.   if (UICurrentFtypeEntry == NULL)
  1362.     return( KRERR_FTYPE_ENTRY );   /*  Current Ftype entry isn't defined   */
  1363.  
  1364.   if (Ftype_symbol == NULL)
  1365.     return( KRERR_FTYPE_NAME );    /*  Ftype name isn't definite   */
  1366.  
  1367.   if (!kr_symbolCheck( Ftype_symbol ))
  1368.     return( KRERR_SYMBOL );  /*  Symbol pattern invalid (must match [A-Za-z]^[|, ]*)  */
  1369.  
  1370.   if (krm_NTableSymbolSearch( Ftype_symbol, FTYPE_UNIT_SYM ) != NULL)
  1371.     return( KRERR_FTYPE_NAME );    /*  Ftype name isn't definite   */
  1372.  
  1373.   if ( (NTable_ptr = krm_NTableCreateEntry( Ftype_symbol, FTYPE_UNIT_SYM ) ) == NULL)
  1374.     return( KRERR_INSUFFICIENT_MEM );  /*  Insufficient memory  */
  1375.  
  1376.   krm_NTableReleaseEntry( UICurrentFtypeEntry->Ftype_symbol );
  1377.  
  1378.   UICurrentFtypeEntry->Ftype_symbol = NTable_ptr;
  1379.  
  1380.   return( KRERR_NO_ERROR );
  1381. }
  1382.  
  1383. /*****************************************************************************
  1384.   FUNCTION : krui_getFTypeActFuncName
  1385.  
  1386.   PURPOSE  : 
  1387.   NOTES    : 
  1388.  
  1389.   RETURNS  : Returns the name of the activation function in the current
  1390.              FType entry
  1391.   UPDATE   : 
  1392. ******************************************************************************/
  1393. char  *krui_getFTypeActFuncName(void)
  1394. {
  1395.   static char  act_func_name[FUNCTION_NAME_MAX_LEN];
  1396.  
  1397.  
  1398.   if (UICurrentFtypeEntry == NULL)
  1399.     return( NULL );
  1400.  
  1401.   strcpy( act_func_name, krf_getFuncName( (FunctionPtr) UICurrentFtypeEntry->act_func ) );
  1402.  
  1403.   return( act_func_name );
  1404. }
  1405.  
  1406. /*****************************************************************************
  1407.   FUNCTION : krui_setFTypeActFunc
  1408.  
  1409.   PURPOSE  : 
  1410.   NOTES    : All units (in the existing network) of the current Ftype changes
  1411.              their activation function.
  1412.  
  1413.   RETURNS  : Sets the activation function in the current FType entry
  1414.              returns 0, if the function is a valid activation function,
  1415.              error code otherwise.
  1416.   UPDATE   : 
  1417. ******************************************************************************/
  1418. krui_err  krui_setFTypeActFunc(char *act_func_name)
  1419. {
  1420.   FunctionPtr  act_func_ptr, act_deriv_func_ptr;
  1421.  
  1422.  
  1423. #ifdef MASPAR_KERNEL
  1424.   MASPAR_FF1_VALIDATE_OP;
  1425. #endif
  1426.  
  1427.   KernelErrorCode = KRERR_NO_ERROR;
  1428.   if (UICurrentFtypeEntry == NULL)
  1429.     {  /*  Current Ftype entry isn't defined   */
  1430.     KernelErrorCode = KRERR_FTYPE_ENTRY;
  1431.     return( KernelErrorCode );
  1432.   }
  1433.  
  1434.   if ( !krf_funcSearch( act_func_name, ACT_FUNC, &act_func_ptr ) )
  1435.     return( KernelErrorCode );
  1436.   /*  set the derivation function of the activation function  */ 
  1437.   if ( !krf_funcSearch( act_func_name, ACT_DERIV_FUNC, &act_deriv_func_ptr ))
  1438.     return( KernelErrorCode );
  1439.  
  1440.   UICurrentFtypeEntry->act_func = (ActFuncPtr) act_func_ptr;
  1441.   UICurrentFtypeEntry->act_deriv_func = (ActDerivFuncPtr) act_deriv_func_ptr;
  1442.  
  1443.   kr_changeFtypeUnits( UICurrentFtypeEntry );
  1444.   return( KernelErrorCode );
  1445. }
  1446.  
  1447.  
  1448. /*  Returns the name of the output function in the current
  1449.     FType entry.
  1450. */
  1451. char  *krui_getFTypeOutFuncName(void)
  1452. {
  1453.   static char  out_func_name[FUNCTION_NAME_MAX_LEN];
  1454.  
  1455.   if (UICurrentFtypeEntry == NULL)
  1456.     return( NULL );
  1457.  
  1458.   strcpy( out_func_name, krf_getFuncName( (FunctionPtr) UICurrentFtypeEntry->out_func ) );
  1459.  
  1460.   return( out_func_name );
  1461. }
  1462.  
  1463.  
  1464. /*****************************************************************************
  1465.   FUNCTION : krui_setFTypeOutFunc
  1466.  
  1467.   PURPOSE  : Sets the output function in the current FType entry
  1468.   NOTES    : All units (in the existing network) of the current Ftype changes
  1469.              their output function.
  1470.  
  1471.   RETURNS  : Returns 0, if the function is a valid output function,
  1472.              error code otherwise.
  1473.   UPDATE   : 
  1474. ******************************************************************************/
  1475. krui_err   krui_setFTypeOutFunc(char *out_func_name)
  1476. {
  1477.   FunctionPtr     out_func_ptr;
  1478.  
  1479.  
  1480.   KernelErrorCode = KRERR_NO_ERROR;
  1481.   if (UICurrentFtypeEntry == NULL)
  1482.     {  /*  Current Ftype entry isn't defined   */
  1483.     KernelErrorCode = KRERR_FTYPE_ENTRY;
  1484.     return( KernelErrorCode );
  1485.   }
  1486.  
  1487.   if ( !krf_funcSearch( out_func_name, OUT_FUNC, &out_func_ptr ) )
  1488.     return( KernelErrorCode );
  1489.  
  1490.   UICurrentFtypeEntry->out_func = (OutFuncPtr) out_func_ptr;
  1491.  
  1492.   kr_changeFtypeUnits( UICurrentFtypeEntry );
  1493.   return( KernelErrorCode );
  1494. }
  1495.  
  1496.  
  1497.  
  1498. /*  FType sites
  1499. */
  1500.  
  1501. /*****************************************************************************
  1502.   FUNCTION : krui_setFirstFTypeSite
  1503.  
  1504.   PURPOSE  : Initializes the first site of the current FType.
  1505.   NOTES    : 
  1506.  
  1507.   RETURNS  : Returns FALSE, if no sites are available in the current
  1508.              FType entry.
  1509.   UPDATE   : 
  1510. ******************************************************************************/
  1511. bool  krui_setFirstFTypeSite(void)
  1512. {
  1513.   if (UICurrentFtypeEntry == NULL)  {
  1514.     UICurrentFtypeSite = NULL;
  1515.     return( FALSE );
  1516.   }
  1517.  
  1518.   if (UICurrentFtypeEntry->sites == NULL)  {
  1519.     UICurrentFtypeSite = NULL;
  1520.     return( FALSE );
  1521.   }
  1522.   else  {
  1523.     UICurrentFtypeSite = UICurrentFtypeEntry->sites;
  1524.     return( TRUE );
  1525.   }
  1526. }
  1527.  
  1528. /*****************************************************************************
  1529.   FUNCTION : krui_setNextFTypeSite
  1530.  
  1531.   PURPOSE  : Initializes the next FType site. 
  1532.   NOTES    : 
  1533.  
  1534.   RETURNS  : Returns FALSE, if no more sites are available in the current
  1535.              FType entry.
  1536.   UPDATE   : 
  1537. ******************************************************************************/
  1538. bool  krui_setNextFTypeSite(void)
  1539. {
  1540.   if (UICurrentFtypeSite == NULL)
  1541.     return( FALSE );
  1542.  
  1543.   if (UICurrentFtypeSite->next == NULL)
  1544.     return( FALSE );
  1545.  
  1546.   UICurrentFtypeSite = UICurrentFtypeSite->next;
  1547.   return( TRUE );
  1548. }
  1549.  
  1550. /*****************************************************************************
  1551.   FUNCTION : krui_getFTypeSiteName
  1552.  
  1553.   PURPOSE  : 
  1554.   NOTES    : 
  1555.  
  1556.   RETURNS  : Returns the name of the current FType site (in the current
  1557.              Ftype entry). 
  1558.   UPDATE   : 
  1559. ******************************************************************************/
  1560. char  *krui_getFTypeSiteName(void)
  1561. {
  1562.   if (UICurrentFtypeSite == NULL)
  1563.     return( NULL );
  1564.  
  1565.   return( ((UICurrentFtypeSite->site_table)->Entry.site_name)->Entry.symbol );
  1566. }
  1567.  
  1568.  
  1569. /*****************************************************************************
  1570.   FUNCTION : krui_setFTypeSiteName
  1571.  
  1572.   PURPOSE  : Sets the name and function of the current FType site (in the
  1573.              current FType entry).
  1574.              All sites (in the existing network) of the current Ftype and the
  1575.              same (old) name changes their names and site functions.
  1576.  
  1577.   NOTES    : 
  1578.  
  1579.   RETURNS  : Returns an error code if
  1580.              - current Ftype site isn't defined
  1581.              - site name does not exist in the site name table
  1582.              0 otherwise.
  1583.   UPDATE   : 
  1584. ******************************************************************************/
  1585. krui_err  krui_setFTypeSiteName(char *FType_site_name)
  1586. {
  1587.   struct  SiteTable     *stbl_ptr;
  1588.  
  1589.  
  1590. #ifdef MASPAR_KERNEL
  1591.   MASPAR_FF1_VALIDATE_OP;
  1592. #endif
  1593.  
  1594.   KernelErrorCode = KRERR_NO_ERROR;
  1595.   if (UICurrentFtypeEntry == NULL)
  1596.     {  /*  Current Ftype entry isn't defined   */
  1597.     KernelErrorCode = KRERR_FTYPE_ENTRY;
  1598.     return( KernelErrorCode );
  1599.   }
  1600.  
  1601.   if (!kr_symbolCheck( FType_site_name ))
  1602.     return( KernelErrorCode );
  1603.  
  1604.   if ( (stbl_ptr = krm_STableSymbolSearch( FType_site_name )) == NULL)
  1605.     {  /*   site name isn't defined */
  1606.     KernelErrorCode = KRERR_UNDEF_SITE_NAME;
  1607.     return( KernelErrorCode );
  1608.   }
  1609.  
  1610.   kr_changeFtypeSites( UICurrentFtypeEntry, UICurrentFtypeSite->site_table, stbl_ptr);
  1611.   UICurrentFtypeSite->site_table = stbl_ptr;
  1612.  
  1613.   return( KernelErrorCode );
  1614. }
  1615.  
  1616. /*****************************************************************************
  1617.   FUNCTION : 
  1618.  
  1619.   PURPOSE  : Create a new functionality type, needs a definite FType symbol,
  1620.              the unit output and activation function
  1621.              and the number of sites provided for this unit FType.
  1622.              An additional array with N elements of pointers to site names
  1623.              is required for the definition of the sites.
  1624.   NOTES    : The number of Ftype entries and the number of sites per Ftype is
  1625.              only limited by the size of system memory.
  1626.  
  1627.   RETURNS  : Returns error code if:
  1628.              - memory allocation fails
  1629.              - FType name isn't definite (symbol is used for another FType
  1630.                or symbol is a NULL pointer)
  1631.              - one or more site names are undefined
  1632.  
  1633.              0 otherwise.
  1634.   UPDATE   : 
  1635. ******************************************************************************/
  1636. krui_err  krui_createFTypeEntry(char *Ftype_symbol, char *act_func_name, char *out_func_name, int no_of_sites, char **array_of_site_names)
  1637. {
  1638.   FunctionPtr    act_func, out_func, act_deriv_func;
  1639.   struct  FtypeUnitStruct   *Ftype_entry;
  1640.   struct  SiteTable         *STable_entry;
  1641.   int       i;
  1642.   char      *Ftype_site_name;
  1643.  
  1644.  
  1645.   KernelErrorCode = KRERR_NO_ERROR;
  1646.  
  1647.   if (Ftype_symbol == NULL)
  1648.     {  /*  Ftype name isn't definite   */
  1649.     KernelErrorCode = KRERR_FTYPE_NAME;
  1650.     return( KernelErrorCode );
  1651.   }
  1652.  
  1653.   if (!kr_symbolCheck( Ftype_symbol ))
  1654.     return( KernelErrorCode );
  1655.   if (krm_NTableSymbolSearch( Ftype_symbol, FTYPE_UNIT_SYM ) != NULL)
  1656.     return( KernelErrorCode );
  1657.   if ( !krf_funcSearch( out_func_name, OUT_FUNC, &out_func ) )
  1658.     return( KernelErrorCode );
  1659.   if ( !krf_funcSearch( act_func_name, ACT_FUNC, &act_func ) )
  1660.     return( KernelErrorCode );
  1661.   /*  set the derivation function of the activation function  */ 
  1662.   if ( !krf_funcSearch( act_func_name, ACT_DERIV_FUNC, &act_deriv_func ))
  1663.     return( KernelErrorCode );
  1664.  
  1665.   if ((Ftype_entry = krm_FtypeCreateEntry( Ftype_symbol, (OutFuncPtr) out_func, (ActFuncPtr) act_func,
  1666.                        (ActDerivFuncPtr) act_deriv_func )) == NULL)
  1667.     return( KernelErrorCode );
  1668.  
  1669.   /*  create sites at the Ftype  */
  1670.   for (i = 0; i < no_of_sites; i++)  {
  1671.     if ( (Ftype_site_name = array_of_site_names[ i ]) == NULL)
  1672.       {  /*   site name isn't defined because it is a NULL pointer  */
  1673.       KernelErrorCode = KRERR_UNDEF_SITE_NAME;
  1674.       return( KernelErrorCode );
  1675.     }
  1676.  
  1677.     if ((STable_entry = krm_STableSymbolSearch( Ftype_site_name )) == NULL)
  1678.       {  /*  site isn't defined  */
  1679.       krm_releaseFtypeEntry( Ftype_entry );
  1680.       KernelErrorCode = KRERR_UNDEF_SITE_NAME;
  1681.       return( KernelErrorCode );
  1682.     }
  1683.  
  1684.     if (krm_FtypeAddSite( Ftype_entry , STable_entry ) == NULL)
  1685.       {  /*  memory alloc failed */
  1686.       krm_releaseFtypeEntry( Ftype_entry );
  1687.       return( KernelErrorCode );
  1688.     }
  1689.   }
  1690.  
  1691.   return( KernelErrorCode );
  1692. }
  1693.  
  1694. /*****************************************************************************
  1695.   FUNCTION : krui_deleteFTypeEntry
  1696.  
  1697.   PURPOSE  : Deletes the specified FType entry. If there exists units in the
  1698.              network with this FType, all these units will lost their FType
  1699.              but the functionality of the units will not be changed.
  1700.   NOTES    : 
  1701.  
  1702.   RETURNS  : Returns error code if FType symbol dosn't exist, 0 otherwise.
  1703.   UPDATE   : 
  1704. ******************************************************************************/
  1705. krui_err    krui_deleteFTypeEntry(char *Ftype_symbol)
  1706. {
  1707.   struct  FtypeUnitStruct   *ftype_ptr;
  1708.  
  1709.  
  1710.   if ( (ftype_ptr = krm_FtypeSymbolSearch( Ftype_symbol ) ) == NULL)
  1711.     return( KRERR_FTYPE_SYMBOL );   /*  FType symbol isn't defined  */
  1712.  
  1713.   kr_deleteUnitsFtype( ftype_ptr );
  1714.   krm_releaseFtypeEntry( ftype_ptr );
  1715.   return( KRERR_NO_ERROR );
  1716. }
  1717.  
  1718.  
  1719.  
  1720. /*#################################################
  1721.  
  1722. GROUP: Functions for reading of the function table
  1723.  
  1724. #################################################*/
  1725. /*****************************************************************************
  1726.   FUNCTION : krui_getNoOfFunctions
  1727.  
  1728.   PURPOSE  : 
  1729.   NOTES    : 
  1730.  
  1731.   RETURNS  : Returns the number of available functions
  1732.   UPDATE   : 
  1733. ******************************************************************************/
  1734. int  krui_getNoOfFunctions(void)
  1735. {
  1736.   return( krf_getNoOfFuncs() );
  1737. }
  1738.  
  1739. /*****************************************************************************
  1740.   FUNCTION : krui_getFuncInfo
  1741.  
  1742.   PURPOSE  : 
  1743.   NOTES    : 
  1744.  
  1745.   RETURNS  : Returns the name of the function and the function type (Output,
  1746.              Activation, Site).
  1747.   UPDATE   : 
  1748. ******************************************************************************/
  1749. void  krui_getFuncInfo(int func_no, char **func_name, int *func_type)
  1750. {
  1751.   static struct FuncInfoDescriptor  functionDescr;
  1752.  
  1753.   functionDescr.number = func_no - 1;
  1754.   KernelErrorCode = krf_getFuncInfo( GET_FUNC_INFO, &functionDescr );
  1755.  
  1756.   *func_type = functionDescr.func_type;
  1757.   *func_name = functionDescr.func_name;
  1758.  
  1759.  
  1760. }
  1761.  
  1762. /*****************************************************************************
  1763.   FUNCTION : krui_isFunction
  1764.  
  1765.   PURPOSE  : 
  1766.   NOTES    : 
  1767.  
  1768.   RETURNS  : Returns true if the given function name and type exists.
  1769.   UPDATE   : 
  1770. ******************************************************************************/
  1771. bool  krui_isFunction(char *func_name, int func_type)
  1772. {
  1773.   FunctionPtr  dummy_func_ptr;
  1774.   bool    is_func;
  1775.  
  1776.   is_func = krf_funcSearch( func_name, func_type, &dummy_func_ptr );
  1777.   KernelErrorCode = KRERR_NO_ERROR;
  1778.   return( is_func );
  1779. }
  1780.  
  1781. /*****************************************************************************
  1782.   FUNCTION : krui_getFuncParamInfo
  1783.  
  1784.   PURPOSE  : Returns the no. of input and output parameters of the given
  1785.              function (only relevant for learning, update and initialisation
  1786.              functions).
  1787.   NOTES    : 
  1788.  
  1789.   RETURNS  : Returns TRUE if the given function exists, FALSE otherwise.
  1790.   UPDATE   : 
  1791. ******************************************************************************/
  1792. bool  krui_getFuncParamInfo(char *func_name, int func_type, int *no_of_input_params, int *no_of_output_params)
  1793. {
  1794.   static struct FuncInfoDescriptor  functionDescr;
  1795.  
  1796.   functionDescr.func_type = func_type;
  1797.   strcpy( functionDescr.func_name, func_name );
  1798.  
  1799.   KernelErrorCode = krf_getFuncInfo( SEARCH_FUNC, &functionDescr );
  1800.  
  1801.   if (KernelErrorCode != KRERR_NO_ERROR)  return( FALSE );
  1802.  
  1803.   *no_of_input_params = functionDescr.no_of_input_parameters;
  1804.   *no_of_output_params = functionDescr.no_of_output_parameters;
  1805.   return( TRUE );
  1806. }
  1807.  
  1808.  
  1809.  
  1810. /*#################################################
  1811.  
  1812. GROUP: Site Table Functions
  1813.  
  1814. #################################################*/
  1815.  
  1816. /*****************************************************************************
  1817.   FUNCTION : krui_getFirstSiteTableEntry
  1818.  
  1819.   PURPOSE  : 
  1820.   NOTES    : 
  1821.  
  1822.   RETURNS  : Returns the first site name/function pair in the site table.
  1823.              Returns FALSE and NULL, if not available.
  1824.   UPDATE   : 
  1825. ******************************************************************************/
  1826. bool   krui_getFirstSiteTableEntry(char **site_name, char **site_func)
  1827. {
  1828.   struct  SiteTable   *s_ptr;
  1829.  
  1830.  
  1831.   if ( (s_ptr = krm_getSTableFirstEntry() ) == NULL)
  1832.     {
  1833.     *site_name = NULL;
  1834.     *site_func = NULL;
  1835.     return( FALSE );
  1836.     }
  1837.   else
  1838.     {
  1839.     *site_name = (s_ptr->Entry.site_name)->Entry.symbol;
  1840.     *site_func = krf_getFuncName( (FunctionPtr) s_ptr->site_func );
  1841.     return( TRUE );
  1842.     }
  1843. }
  1844.  
  1845.  
  1846. /*****************************************************************************
  1847.   FUNCTION : krui_getNextSiteTableEntry
  1848.  
  1849.   PURPOSE  : 
  1850.   NOTES    : 
  1851.  
  1852.   RETURNS  : Returns the next site name/function pair in the site table.
  1853.              Returns FALSE and NULL, if not available.
  1854.   UPDATE   : 
  1855. ******************************************************************************/
  1856. bool  krui_getNextSiteTableEntry(char **site_name, char **site_func)
  1857. {
  1858.   struct  SiteTable   *s_ptr;
  1859.  
  1860.  
  1861.   if ( (s_ptr = krm_getSTableNextEntry() ) == NULL)
  1862.     {
  1863.     *site_name = NULL;
  1864.     *site_func = NULL;
  1865.     return( FALSE );
  1866.     }
  1867.   else
  1868.     {
  1869.     *site_name = (s_ptr->Entry.site_name)->Entry.symbol;
  1870.     *site_func = krf_getFuncName( (FunctionPtr) s_ptr->site_func );
  1871.     return( TRUE );
  1872.     }
  1873. }
  1874.  
  1875. /*****************************************************************************
  1876.   FUNCTION : krui_getSiteTableFuncName
  1877.  
  1878.   PURPOSE  : 
  1879.   NOTES    : 
  1880.  
  1881.   RETURNS  : Returns the name of the site function that is associated with
  1882.              the site name.
  1883.              If the site name do not exist, function returns NULL.
  1884.   UPDATE   : 
  1885. ******************************************************************************/
  1886. char  *krui_getSiteTableFuncName(char *site_name)
  1887. {
  1888.   struct SiteTable  *s_ptr;
  1889.  
  1890.  
  1891.   if ( (s_ptr = krm_STableSymbolSearch( site_name )) == NULL)
  1892.     return( NULL );
  1893.  
  1894.   return( krf_getFuncName( (FunctionPtr) s_ptr->site_func ) );
  1895. }
  1896.  
  1897.  
  1898. /*****************************************************************************
  1899.   FUNCTION : krui_createSiteTableEntry
  1900.  
  1901.   PURPOSE  : Creates a new site name and associate this name with a site
  1902.              function.
  1903.   NOTES    : 
  1904.  
  1905.   RETURNS  : Returns error code if:
  1906.              - site name already exists or
  1907.              - site function is invalid or
  1908.              - memory allocation has failed
  1909.             0 otherwise.
  1910.   UPDATE   : 
  1911. ******************************************************************************/
  1912. krui_err  krui_createSiteTableEntry(char *site_name, char *site_func)
  1913. {
  1914.   FunctionPtr   func_ptr;
  1915.  
  1916.   KernelErrorCode = KRERR_NO_ERROR;
  1917.   if ( !krf_funcSearch( site_func, SITE_FUNC, &func_ptr ) )
  1918.     return( KernelErrorCode );
  1919.   if (!kr_symbolCheck( site_name ))
  1920.     return( KernelErrorCode );
  1921.   if (krm_STableSymbolSearch( site_name ) != NULL)
  1922.     {  /*  symbol is already in the site table */
  1923.     KernelErrorCode = KRERR_REDEF_SITE_NAME;
  1924.     return( KernelErrorCode );
  1925.   }
  1926.  
  1927.   (void) krm_STableCreateEntry( site_name, (SiteFuncPtr) func_ptr );
  1928.  
  1929.   return( KernelErrorCode );
  1930. }
  1931.  
  1932. /*****************************************************************************
  1933.   FUNCTION : krui_changeSiteTableEntry
  1934.  
  1935.   PURPOSE  : Changes the site function of a previously defined site name.
  1936.   NOTES    : All sites in the network with the name <old_site_name>
  1937.              changes their names and functions.
  1938.  
  1939.   RETURNS  : Returns error code if <old_site_name> or <new_site_func>
  1940.              isn't defined, 0 otherwise.
  1941.   UPDATE   : 
  1942. ******************************************************************************/
  1943. krui_err  krui_changeSiteTableEntry(char *old_site_name, char *new_site_name, char *new_site_func)
  1944. {
  1945.   FunctionPtr   func_ptr;
  1946.   SiteFuncPtr        site_func_ptr;
  1947.   struct SiteTable  *stbl_ptr1,
  1948.                     *stbl_ptr2;
  1949.  
  1950. #ifdef MASPAR_KERNEL
  1951.   MASPAR_FF1_VALIDATE_OP;
  1952. #endif
  1953.  
  1954.   KernelErrorCode = KRERR_NO_ERROR;
  1955.   if (!kr_symbolCheck( new_site_name ))
  1956.     return( KernelErrorCode );
  1957.   if ( !krf_funcSearch( new_site_func, SITE_FUNC, &func_ptr ) )
  1958.     return( KernelErrorCode );
  1959.  
  1960.   site_func_ptr = (SiteFuncPtr) func_ptr;
  1961.  
  1962.   if ( (stbl_ptr1 = krm_STableSymbolSearch( old_site_name )) == NULL)
  1963.     {  /*  old site name isn't defined */
  1964.     KernelErrorCode = KRERR_UNDEF_SITE_NAME;
  1965.     return( KernelErrorCode );
  1966.   }
  1967.  
  1968.   stbl_ptr2 = krm_STableSymbolSearch( new_site_name );
  1969.   if ( (stbl_ptr2 != NULL) && (stbl_ptr2 != stbl_ptr1) )
  1970.     {  /*  new symbol is already in the site table (and new_site_name and
  1971.        old_site_name are not identical) */
  1972.     KernelErrorCode = KRERR_REDEF_SITE_NAME;
  1973.     return( KernelErrorCode );
  1974.   }
  1975.  
  1976.   (void) krm_STableChangeEntry( stbl_ptr1 , new_site_name , site_func_ptr );
  1977.   return( KernelErrorCode );
  1978. }
  1979.  
  1980. /*****************************************************************************
  1981.   FUNCTION : krui_deleteSiteTableEntry
  1982.  
  1983.   PURPOSE  : Removes the current site name entry from the site table.
  1984.   NOTES    : 
  1985.  
  1986.   RETURNS  : Returns an error code if
  1987.              - there exists sites with the given name in the network or
  1988.              - <site_name> isn't defined
  1989.              0 otherwise.
  1990.   UPDATE   : 
  1991. ******************************************************************************/
  1992. krui_err  krui_deleteSiteTableEntry(char *site_name)
  1993. {
  1994.   struct SiteTable    *st_ptr;
  1995.  
  1996.  
  1997.   if ((st_ptr = krm_STableSymbolSearch( site_name )) == NULL)
  1998.     return( KRERR_UNDEF_SITE_NAME );   /*  Site name isn't defined */
  1999.  
  2000.   if (kr_searchNetSite( st_ptr ) != 0)
  2001.     return( KRERR_INUSE_SITE );   /*  Site is in use and must not be deleted  */
  2002.  
  2003.   krm_STableRemoveEntry( st_ptr );
  2004.   return( KRERR_NO_ERROR );
  2005. }
  2006.  
  2007.  
  2008. /*#################################################
  2009.  
  2010. GROUP: Site Functions
  2011.  
  2012. #################################################*/
  2013. /*****************************************************************************
  2014.   FUNCTION : krui_setFirstSite
  2015.  
  2016.   PURPOSE  : Initializes the first site at the current unit.
  2017.   NOTES    : 
  2018.  
  2019.   RETURNS  : Returns false if no site available or if no sites permitted at this unit.
  2020.   UPDATE   : 
  2021. ******************************************************************************/
  2022. bool  krui_setFirstSite(void)
  2023. {
  2024.   if KERNEL_STANDARD
  2025.     return( kr_setSite( FIRST, NULL ) );
  2026.  
  2027.   KernelErrorCode = KRERR_SITES_NO_SUPPORT;
  2028.   return( FALSE );
  2029. }
  2030.  
  2031. /*****************************************************************************
  2032.   FUNCTION : krui_setNextSite
  2033.  
  2034.   PURPOSE  : Initializes the next site at the current unit.
  2035.   NOTES    : 
  2036.  
  2037.   RETURNS  : Returns false if no more sites available.
  2038.   UPDATE   : 
  2039. ******************************************************************************/
  2040. bool  krui_setNextSite(void)
  2041. {
  2042.   if KERNEL_STANDARD
  2043.     return( kr_setSite( NEXT, NULL ) );
  2044.  
  2045.   KernelErrorCode = KRERR_SITES_NO_SUPPORT;
  2046.   return( FALSE );
  2047. }
  2048.  
  2049. /*****************************************************************************
  2050.   FUNCTION : krui_setSite
  2051.  
  2052.   PURPOSE  : Initializes the given site at the current unit.
  2053.   NOTES    : 
  2054.  
  2055.   RETURNS  : Returns error code if
  2056.              - unit dosn't exist
  2057.              - site name doesn't exist
  2058.              - unit don't has sites
  2059.              - unit don't has a site with this name
  2060.              0 otherwise.
  2061.   UPDATE   : 
  2062. ******************************************************************************/
  2063. krui_err  krui_setSite(char *site_name)
  2064. {
  2065.   if KERNEL_STANDARD
  2066.     return( kr_setSite( NAME, site_name ) );
  2067.  
  2068.   KernelErrorCode = KRERR_SITES_NO_SUPPORT;
  2069.   return( KernelErrorCode );
  2070. }
  2071.  
  2072.  
  2073. /*****************************************************************************
  2074.   FUNCTION : krui_getSiteValue
  2075.  
  2076.   PURPOSE  : 
  2077.   NOTES    : 
  2078.  
  2079.   RETURNS  : Returns the actual value of the current site
  2080.   UPDATE   : 
  2081. ******************************************************************************/
  2082. FlintType   krui_getSiteValue(void)
  2083. {
  2084.   if KERNEL_STANDARD
  2085.     {
  2086.     if (sitePtr == NULL)
  2087.       KernelErrorCode = KRERR_NO_SITES;
  2088.     else
  2089.       return( (*sitePtr->site_table->site_func) (sitePtr) );
  2090.     }
  2091.   else
  2092.     KernelErrorCode = KRERR_SITES_NO_SUPPORT;
  2093.  
  2094.   return( (FlintType) 0 );
  2095. }
  2096.  
  2097.  
  2098. /*****************************************************************************
  2099.   FUNCTION : krui_getSiteName
  2100.  
  2101.   PURPOSE  : 
  2102.   NOTES    : 
  2103.  
  2104.   RETURNS  : returns the name of the current unit/site,
  2105.              NULL if not available.
  2106.   UPDATE   : 
  2107. ******************************************************************************/
  2108. char  *krui_getSiteName(void)
  2109. {
  2110.   if KERNEL_STANDARD
  2111.     {
  2112.     if (sitePtr == NULL)
  2113.       KernelErrorCode = KRERR_NO_SITES;
  2114.     else
  2115.      return( ((sitePtr->site_table)->Entry.site_name)->Entry.symbol );
  2116.     }
  2117.   else
  2118.     KernelErrorCode = KRERR_SITES_NO_SUPPORT;
  2119.  
  2120.   return( NULL );
  2121. }
  2122.  
  2123. /*****************************************************************************
  2124.   FUNCTION : krui_setSiteName
  2125.  
  2126.   PURPOSE  : Sets the name/function of the current unit/site.
  2127.              Current Unit will loose the functionality type.
  2128.   NOTES    : 
  2129.  
  2130.   RETURNS  : Returns error code if site name isn't defined.
  2131.   UPDATE   : 
  2132. ******************************************************************************/
  2133. krui_err  krui_setSiteName(char *site_name)
  2134. {
  2135.   struct  SiteTable     *stbl_ptr;
  2136.  
  2137. #ifdef MASPAR_KERNEL
  2138.   MASPAR_FF1_VALIDATE_OP;
  2139. #endif
  2140.  
  2141.   if (sitePtr == NULL)
  2142.     {
  2143.     KernelErrorCode = KRERR_FTYPE_SITE;
  2144.     return( KernelErrorCode );
  2145.   }
  2146.  
  2147.   if (!kr_symbolCheck( site_name ))
  2148.     return( KernelErrorCode );
  2149.   if ((stbl_ptr = krm_STableSymbolSearch( site_name )) == NULL)
  2150.     {  /*   site name isn't defined */
  2151.     KernelErrorCode = KRERR_UNDEF_SITE_NAME;
  2152.     return( KernelErrorCode );
  2153.   }
  2154.  
  2155.   KernelErrorCode = KRERR_NO_ERROR;
  2156.   unitPtr->Ftype_entry = NULL;
  2157.   sitePtr->site_table  = stbl_ptr;
  2158.  
  2159.   NetModified = TRUE;
  2160.  
  2161.   return( KRERR_NO_ERROR );
  2162. }
  2163.  
  2164. /*****************************************************************************
  2165.   FUNCTION : krui_getSiteFuncName
  2166.  
  2167.   PURPOSE  : 
  2168.   NOTES    : 
  2169.  
  2170.   RETURNS  : Returns the name of the current unit/site function
  2171.   UPDATE   : 
  2172. ******************************************************************************/
  2173. char  *krui_getSiteFuncName(void)
  2174. {
  2175.   static char  site_func_name[FUNCTION_NAME_MAX_LEN];
  2176.  
  2177.   if (sitePtr == NULL)
  2178.     {
  2179.     KernelErrorCode = KRERR_FTYPE_SITE;
  2180.     return( NULL );
  2181.   }
  2182.  
  2183.   strcpy( site_func_name, krf_getFuncName( (FunctionPtr) sitePtr->site_table->site_func ) );
  2184.  
  2185.   return( site_func_name );
  2186. }
  2187.  
  2188.  
  2189. /*****************************************************************************
  2190.   FUNCTION : krui_addSite
  2191.  
  2192.   PURPOSE  : Adds a site at the current unit. If the unit has already sites, this new
  2193.              site will be inserted above all other sites, i.e. the new created site will
  2194.              be the first site at this unit.
  2195.              If the unit has direct input links, i.e the unit has input links
  2196.              but no sites, the creation of sites is not permitted (krui_addSite will
  2197.              return an error code).
  2198.              If there exists already a site with the given name, the creation of the
  2199.              new site is prohibited and krui_addSite returns an error code.
  2200.  
  2201.              krui_addSite has no effect on the current site. To change the current site
  2202.              to this new site, call krui_setFirstSite().
  2203.              The unit's FType will be deleted.
  2204.   NOTES    : The number of sites per unit is nearly unlimited (2^32).
  2205.  
  2206.   RETURNS  : Returns error code if
  2207.              - memory allocation fails or
  2208.              - unit has direct input links or
  2209.              - site name isn't defined or
  2210.              - site with the given name exists already at this unit
  2211.              0 otherwise.
  2212.   UPDATE   : 
  2213. ******************************************************************************/
  2214. krui_err  krui_addSite(char *site_name)
  2215. {
  2216.   FlagWord    flags;
  2217.   struct Site       *site_ptr,
  2218.                     *site_ptr1;
  2219.   struct SiteTable  *stbl_ptr;
  2220.  
  2221.  
  2222. #ifdef MASPAR_KERNEL
  2223.   MASPAR_FF1_VALIDATE_OP;
  2224. #endif
  2225.  
  2226.   KernelErrorCode = KRERR_NO_ERROR;
  2227.   if ( (stbl_ptr = krm_STableSymbolSearch( site_name )) == NULL)
  2228.     {  /*  site name isn't defined */
  2229.     KernelErrorCode = KRERR_UNDEF_SITE_NAME;
  2230.     return( KernelErrorCode );
  2231.   }
  2232.  
  2233.   flags = unitPtr->flags & UFLAG_INPUT_PAT;
  2234.  
  2235.   switch (flags)
  2236.     {
  2237.     case UFLAG_NO_INP :
  2238.         /*  Unit has no inputs  */
  2239.     if ((site_ptr = kr_createDefaultSite() ) == NULL)
  2240.       return( KernelErrorCode );
  2241.  
  2242.     unitPtr->sites = site_ptr;     /*  Connect site    */
  2243.     unitPtr->flags |= UFLAG_SITES; /*  Set site flag   */
  2244.     unitPtr->Ftype_entry = NULL;   /*  Delete Ftype    */
  2245.  
  2246.         break;
  2247.  
  2248.     case UFLAG_SITES :
  2249.         /*  Unit has already sites  */
  2250.     if (kr_searchUnitSite( unitPtr, stbl_ptr ) != NULL)
  2251.       {  /*  there exists already a site with this name at this unit   */
  2252.       KernelErrorCode = KRERR_DUPLICATED_SITE;
  2253.       return( KernelErrorCode );
  2254.     }
  2255.  
  2256.         if ( (site_ptr = kr_createDefaultSite() ) == NULL)
  2257.       return( KernelErrorCode );
  2258.  
  2259.     site_ptr1 = unitPtr->sites;
  2260.     unitPtr->sites = site_ptr;     /*  Connect site    */
  2261.         site_ptr->next = site_ptr1;
  2262.     unitPtr->Ftype_entry = NULL;   /*  Delete Ftype    */
  2263.  
  2264.         break;
  2265.  
  2266.     case UFLAG_DLINKS :
  2267.         /*  Unit has direct input links and can't have sites */
  2268.     KernelErrorCode = KRERR_CREATE_SITE;
  2269.     return( KernelErrorCode );
  2270.  
  2271.     default :
  2272.     KernelErrorCode = KRERR_CREATE_SITE;
  2273.     return( KernelErrorCode );
  2274.     }
  2275.  
  2276.   site_ptr->site_table = stbl_ptr;
  2277.  
  2278.   NetModified = TRUE;
  2279.   return( KernelErrorCode );
  2280. }
  2281.  
  2282. /*****************************************************************************
  2283.   FUNCTION : krui_deleteSite
  2284.  
  2285.   PURPOSE  : Removes the current site at the current unit and removes all
  2286.              links from predecessor units to this site.
  2287.              krui_setFirstSite (krui_setNextSite) must be called at least once
  2288.              before using this function.
  2289.              The current site will be set to the next available site, if no more
  2290.              sites available, krui_deleteSite returns 0 otherwise 1.
  2291.              Returns an error code if ther was a problem.
  2292.              The unit's FType will be set to 0, i.e. the unit's functionality
  2293.              type will be deleted.
  2294.  
  2295.   NOTES    : To delete all sites at a unit:
  2296.                if ( krui_setFirstSite() )
  2297.                    while ( krui_deleteSite() > 0) { }
  2298.  
  2299.   RETURNS  : 
  2300.   UPDATE   : 
  2301. ******************************************************************************/
  2302. bool  krui_deleteSite(void)
  2303. {
  2304.   struct Site   *next_site_ptr;
  2305.   struct Unit   *unit_ptr;
  2306.  
  2307.  
  2308. #ifdef MASPAR_KERNEL
  2309.   MASPAR_FF1_VALIDATE_OP;
  2310. #endif
  2311.  
  2312.   unit_ptr = unitPtr;
  2313.  
  2314.   if ( UNIT_HAS_SITES( unit_ptr ) &&
  2315.        (unit_ptr->sites != NULL) &&
  2316.        (sitePtr != NULL)   )
  2317.     {   /*  Unit has sites  */
  2318.     NetModified = TRUE;
  2319.  
  2320.     next_site_ptr = sitePtr->next;
  2321.  
  2322.     krm_releaseAllLinks( sitePtr->links );  /*    Remove links    */
  2323.     krm_releaseSite( sitePtr );         /*    Remove site    */
  2324.  
  2325.     if (prevSitePtr == NULL)
  2326.       {     /*  This site is the first site at the current unit */
  2327.  
  2328.       if (next_site_ptr == NULL)
  2329.         {   /*  Unit has only this site */
  2330.         unit_ptr->sites = NULL;                 /*  Clear site pointer  */
  2331.         unit_ptr->flags &= (~UFLAG_INPUT_PAT);  /*  Clear input flags   */
  2332.  
  2333.     sitePtr     = NULL;           /*  No more sites available  */
  2334.     prevSitePtr = NULL;
  2335.         }
  2336.       else
  2337.         {   /*  It is the first site at the unit but not the only one   */
  2338.         unit_ptr->sites  = next_site_ptr;       /*  Connect the other sites */
  2339.     sitePtr = next_site_ptr;       /*  Current site ptr points to the next site    */
  2340.         }
  2341.       }
  2342.     else
  2343.       {     /*  This is not the first site at the unit  */
  2344.       prevSitePtr->next = next_site_ptr;   /*  Connect the previous site
  2345.                                                         with the next site  */
  2346.       sitePtr = next_site_ptr; /*  Current site ptr points to the next site    */
  2347.       }
  2348.  
  2349.     unit_ptr->Ftype_entry = NULL;   /*  Delete unit's Ftype */
  2350.     }
  2351.  
  2352.   if (sitePtr != NULL)
  2353.     return( TRUE );  /*  Returns TRUE if more sites available  */
  2354.   else
  2355.     return( FALSE );
  2356. }
  2357.  
  2358.  
  2359.  
  2360. /*#################################################
  2361.  
  2362. GROUP: Link Functions
  2363.  
  2364. #################################################*/
  2365. /*****************************************************************************
  2366.   FUNCTION : krui_getFirstPredUnit
  2367.  
  2368.   PURPOSE  : 
  2369.   NOTES    : If a predecessor unit exists, the current link is set to the link
  2370.              between the two units.
  2371.  
  2372.   RETURNS  : Returns the no. of first predecessor unit of the current unit/site
  2373.              and the connection strenght.
  2374.              Returns 0 if no predecessor unit available, i.e. if the current unit
  2375.              and/or site has no inputs. 
  2376.   UPDATE   : 
  2377. ******************************************************************************/
  2378. int  krui_getFirstPredUnit(FlintType *strength)
  2379. {
  2380.   if KERNEL_STANDARD  {
  2381.     return( kr_getPredecessorUnit( FIRST, strength ) );
  2382.   }
  2383.   else  {
  2384.  
  2385. #ifdef MASPAR_KERNEL
  2386.  
  2387.     return( krff_getPredecessorUnit( FIRST, strength ) );
  2388.  
  2389. #else
  2390.  
  2391.     KernelErrorCode = KRERR_NO_MASPAR_KERNEL;
  2392.     return( KernelErrorCode );
  2393.  
  2394. #endif
  2395.   }
  2396. }
  2397.  
  2398. /*****************************************************************************
  2399.   FUNCTION : krui_getNextPredUnit
  2400.  
  2401.   PURPOSE  : Returns the number of the next logical predecessor unit in a TDNN
  2402.   NOTES    : If another predecessor unit exists, the current link is set to 
  2403.              the link between the two units.
  2404.  
  2405.  
  2406.   RETURNS  : Returns the no. of the next predecessor unit of the current
  2407.              unit/site and the connection strenght.
  2408.              Returns 0 if no more predecessor units exists.
  2409.   UPDATE   : 
  2410. ******************************************************************************/
  2411. int  krui_getNextPredUnit(FlintType *strength)
  2412. {
  2413.   if KERNEL_STANDARD  {
  2414.     return( kr_getPredecessorUnit( NEXT, strength ) );
  2415.   }
  2416.   else  {
  2417.  
  2418. #ifdef MASPAR_KERNEL
  2419.  
  2420.     return( krff_getPredecessorUnit( NEXT, strength ) );
  2421.  
  2422. #else
  2423.  
  2424.     KernelErrorCode = KRERR_NO_MASPAR_KERNEL;
  2425.     return( KernelErrorCode );
  2426.  
  2427. #endif
  2428.   }
  2429. }
  2430.  
  2431.  
  2432. /*****************************************************************************
  2433.   FUNCTION : krui_getCurrentPredUnit
  2434.  
  2435.   PURPOSE  : 
  2436.   NOTES    : 
  2437.  
  2438.   RETURNS  : Returns the no. of the current predecessor unit (of the current
  2439.              unit/site) and the connection strenght.
  2440.              Returns 0 if no predecessor unit available, i.e. if the current unit
  2441.              and/or site has no inputs 
  2442.   UPDATE   : 
  2443. ******************************************************************************/
  2444. int  krui_getCurrentPredUnit(FlintType *strength)
  2445. {
  2446.   if KERNEL_STANDARD  {
  2447.     return( kr_getPredecessorUnit( CURRENT, strength ) );
  2448.   }
  2449.   else  {
  2450.  
  2451. #ifdef MASPAR_KERNEL
  2452.  
  2453.     return( krff_getPredecessorUnit( CURRENT, strength ) );
  2454.  
  2455. #else
  2456.  
  2457.     KernelErrorCode = KRERR_NO_MASPAR_KERNEL;
  2458.     return( KernelErrorCode );
  2459.  
  2460. #endif
  2461.   }
  2462. }
  2463.  
  2464. /*****************************************************************************
  2465.   FUNCTION : krui_getFirstSuccUnit
  2466.  
  2467.   PURPOSE  : 
  2468.   NOTES    : This function is slow (Units are backward chained only).
  2469.   IMPORTANT: If a successor unit exists, the current unit and site will be
  2470.              set to this successor unit and the attached site.
  2471.  
  2472.   RETURNS  : Returns the no. of the first successor unit of the unit <source_unit_no>
  2473.              and the connection strenght.
  2474.              Returns (negative) error code if unit doesn't exist.
  2475.              Returns 0 if no successor unit available, i.e. if the given unit
  2476.              has no output connection. 
  2477.   UPDATE   : 
  2478. ******************************************************************************/
  2479. int  krui_getFirstSuccUnit(int source_unit_no, FlintType *weight)
  2480. {
  2481.   if KERNEL_STANDARD  {
  2482.     return( kr_getSuccessorUnit( FIRST, source_unit_no, weight ) );
  2483.   }
  2484.   else  {
  2485.  
  2486. #ifdef MASPAR_KERNEL
  2487.  
  2488.     return( krff_getSuccessorUnit( FIRST, source_unit_no, weight ) );
  2489.  
  2490. #else
  2491.  
  2492.     KernelErrorCode = KRERR_NO_MASPAR_KERNEL;
  2493.     return( KernelErrorCode );
  2494.  
  2495. #endif
  2496.   }
  2497. }
  2498.  
  2499. /*****************************************************************************
  2500.   FUNCTION : krui_getNextSuccUnit
  2501.  
  2502.   PURPOSE  : 
  2503.   NOTES    : This function is slow  (Units are backward chained only)
  2504.   IMPORTANT: If a successor unit exists, the current unit and site will be
  2505.              set to this successor unit and the attached site.
  2506.  
  2507.   RETURNS  : Returns the no. of the next successor unit and the connection strenght.
  2508.   UPDATE   : 
  2509. ******************************************************************************/
  2510. int  krui_getNextSuccUnit(FlintType *weight)
  2511. {
  2512.   if KERNEL_STANDARD  {
  2513.     return( kr_getSuccessorUnit( NEXT, 0, weight ) );
  2514.   }
  2515.   else  {
  2516.  
  2517. #ifdef MASPAR_KERNEL
  2518.  
  2519.     return( krff_getSuccessorUnit( NEXT, 0, weight ) );
  2520.  
  2521. #else
  2522.  
  2523.     KernelErrorCode = KRERR_NO_MASPAR_KERNEL;
  2524.     return( KernelErrorCode );
  2525.  
  2526. #endif
  2527.   }
  2528. }
  2529.  
  2530. /*****************************************************************************
  2531.   FUNCTION : krui_areConnected
  2532.  
  2533.   PURPOSE  : True if there exists a connection between source unit <source_unit_no>
  2534.              and target unit <target_unit_no>, otherwise false. If there exist a
  2535.              connection between these units, krui_areConnected returns the connection
  2536.              strength also.
  2537.              Returns FALSE if unit doesn't exist.
  2538.   NOTES    : This function is slow (Units are backward chained only).
  2539.   IMPORTANT: If there exist a connection, the current unit and site will be
  2540.          set to the target unit/site.
  2541.   RETURNS  : 
  2542.   UPDATE   : 
  2543. ******************************************************************************/
  2544. bool  krui_areConnected(int source_unit_no, int target_unit_no, FlintType *weight)
  2545. {
  2546.   if KERNEL_STANDARD  {
  2547.     return( kr_areConnected( source_unit_no, target_unit_no, weight ) );
  2548.   }
  2549.   else  {
  2550.  
  2551. #ifdef MASPAR_KERNEL
  2552.  
  2553.     return( krff_areConnected( source_unit_no, target_unit_no, weight ) );
  2554.  
  2555. #else
  2556.  
  2557.     KernelErrorCode = KRERR_NO_MASPAR_KERNEL;
  2558.     return( FALSE );
  2559.  
  2560. #endif
  2561.   }
  2562. }
  2563.  
  2564.  
  2565. /*****************************************************************************
  2566.   FUNCTION : krui_isConnected
  2567.  
  2568.   PURPOSE  : True if there exists a connection between source unit <source_unit_no>
  2569.               and the current unit/site, otherwise false. 
  2570.   NOTES    : If there exists a connection between the two units, the current link is set
  2571.              to the link between the two units. (alter the link weight with krui_setLinkWeight)
  2572.  
  2573.   RETURNS  : 
  2574.   UPDATE   : 
  2575. ******************************************************************************/
  2576. bool  krui_isConnected(int source_unit_no)
  2577. {
  2578.   FlintType  weight;
  2579.  
  2580.   if KERNEL_STANDARD  {
  2581.     return( kr_isConnected( source_unit_no, &weight ) );
  2582.   }
  2583.   else  {
  2584.  
  2585. #ifdef MASPAR_KERNEL
  2586.  
  2587.     return( krff_isConnected( source_unit_no, &weight ) );
  2588.  
  2589. #else
  2590.  
  2591.     KernelErrorCode = KRERR_NO_MASPAR_KERNEL;
  2592.     return( FALSE );
  2593.  
  2594. #endif
  2595.   }
  2596. }
  2597.  
  2598.  
  2599. /*****************************************************************************
  2600.   FUNCTION : krui_getLinkWeight
  2601.  
  2602.   PURPOSE  : 
  2603.   NOTES    : 
  2604.  
  2605.   RETURNS  : Returns the link weight of the current link.
  2606.   UPDATE   : 
  2607. ******************************************************************************/
  2608. FlintType  krui_getLinkWeight(void)
  2609. {
  2610.   if KERNEL_STANDARD  {
  2611.     return( kr_getLinkWeight() );
  2612.   }
  2613.   else  {
  2614.  
  2615. #ifdef MASPAR_KERNEL
  2616.  
  2617.     return( krff_getLinkWeight() );
  2618.  
  2619. #else
  2620.  
  2621.     KernelErrorCode = KRERR_NO_MASPAR_KERNEL;
  2622.     return( 0.0 );
  2623.  
  2624. #endif
  2625.   }
  2626. }
  2627. /*****************************************************************************
  2628.   FUNCTION : krui_setLinkWeight
  2629.  
  2630.   PURPOSE  : Sets the link weight of the current link
  2631.   NOTES    : 
  2632.  
  2633.   RETURNS  : 
  2634.   UPDATE   : 
  2635. ******************************************************************************/
  2636. void  krui_setLinkWeight(FlintTypeParam weight)
  2637. {
  2638.   if KERNEL_STANDARD  {
  2639.     kr_setLinkWeight( weight );
  2640.   }
  2641.   else  {
  2642.  
  2643. #ifdef MASPAR_KERNEL
  2644.  
  2645.     krff_setLinkWeight( weight );
  2646.  
  2647. #else
  2648.  
  2649.     KernelErrorCode = KRERR_NO_MASPAR_KERNEL;
  2650.  
  2651. #endif
  2652.   }
  2653. }
  2654.  
  2655. /*****************************************************************************
  2656.   FUNCTION : krui_createLink
  2657.  
  2658.   PURPOSE  : Creates a link between source unit and the current unit/site.
  2659.   NOTES    : krui_createLink DO NOT set the current link.
  2660.              If you want to create a link and its unknown if there exists already a
  2661.              connection between the two units, use krui_createLink and test the return
  2662.              code, instead of the sequence krui_isConnected and krui_createLink.
  2663.   RETURNS  : Returns an error code:
  2664.              - if memory allocation fails
  2665.              - if source unit doesn't exist or
  2666.              - if there exists already a connection between current unit/site and
  2667.              the source unit
  2668.              0 otherwise.
  2669.     
  2670.   UPDATE   : 
  2671. ******************************************************************************/
  2672. krui_err  krui_createLink(int source_unit_no, FlintTypeParam weight)
  2673. {
  2674.   if KERNEL_STANDARD  {
  2675.     return( kr_createLink( source_unit_no, weight ) );
  2676.   }
  2677.   else  {
  2678.  
  2679. #ifdef MASPAR_KERNEL
  2680.  
  2681.     return( krff_createLink( source_unit_no, weight ) );
  2682.  
  2683. #else
  2684.  
  2685.     KernelErrorCode = KRERR_NO_MASPAR_KERNEL;
  2686.     return( KernelErrorCode );
  2687.  
  2688. #endif
  2689.   }
  2690. }
  2691.  
  2692. /*****************************************************************************
  2693.   FUNCTION : krui_deleteLink
  2694.  
  2695.   PURPOSE  : Deletes the current link.
  2696.   NOTES    : To delete a link between the current unit/site and the source unit
  2697.              <source_unit_no>, call krui_isConnected( source_unit_no ) and
  2698.              krui_deleteLink().
  2699.  
  2700.   RETURNS  : 
  2701.   UPDATE   : 
  2702. ******************************************************************************/
  2703. krui_err  krui_deleteLink(void)
  2704. {
  2705. #ifdef MASPAR_KERNEL
  2706.   MASPAR_FF1_VALIDATE_OP;
  2707. #endif
  2708.  
  2709.   return( kr_deleteLink() );
  2710. }
  2711.  
  2712. /*****************************************************************************
  2713.   FUNCTION : krui_deleteAllInputLinks
  2714.  
  2715.   PURPOSE  : Deletes all input links at current unit/site.
  2716.   NOTES    : 
  2717.  
  2718.   RETURNS  : 
  2719.   UPDATE   : 
  2720. ******************************************************************************/
  2721. krui_err  krui_deleteAllInputLinks(void)
  2722. {
  2723. #ifdef MASPAR_KERNEL
  2724.   MASPAR_FF1_VALIDATE_OP;
  2725. #endif
  2726.  
  2727.   return( kr_deleteAllLinks( INPUTS ) );
  2728. }
  2729.  
  2730. /*****************************************************************************
  2731.   FUNCTION : krui_deleteAllOutputLinks
  2732.  
  2733.   PURPOSE  : Deletes all output links at current unit.
  2734.   NOTES    : This function is slow.
  2735.  
  2736.   RETURNS  : 
  2737.   UPDATE   : 
  2738. ******************************************************************************/
  2739. krui_err  krui_deleteAllOutputLinks(void)
  2740. {
  2741. #ifdef MASPAR_KERNEL
  2742.   MASPAR_FF1_VALIDATE_OP;
  2743. #endif
  2744.  
  2745.   return( kr_deleteAllLinks( OUTPUTS ) );
  2746. }
  2747.  
  2748. /*****************************************************************************
  2749.   FUNCTION : krui_jogWeights
  2750.  
  2751.   PURPOSE  : Add uniform distributed random values to connection weights.
  2752.              <minus> must be less then <plus>.
  2753.   NOTES    : 
  2754.  
  2755.   RETURNS  : 
  2756.   UPDATE   : 
  2757. ******************************************************************************/
  2758. void  krui_jogWeights(FlintTypeParam minus, FlintTypeParam plus)
  2759. {
  2760.   if (minus >= plus)  {
  2761.     KernelErrorCode = KRERR_PARAMETERS;
  2762.     return;  /*  wrong bounds    */
  2763.   }
  2764.  
  2765.   if KERNEL_STANDARD  {
  2766.     kr_jogWeights( minus, plus );
  2767.   }
  2768.   else  {
  2769.  
  2770. #ifdef MASPAR_KERNEL
  2771.  
  2772.     krff_jogWeights( minus, plus );
  2773.  
  2774. #else
  2775.  
  2776.     KernelErrorCode = KRERR_NO_MASPAR_KERNEL;
  2777.  
  2778. #endif
  2779.   }
  2780. }
  2781.  
  2782.  
  2783.  
  2784. /*#################################################
  2785.  
  2786. GROUP: Functions for network propagation
  2787.  
  2788. #################################################*/
  2789. /*****************************************************************************
  2790.   FUNCTION : krui_updateSingleUnit 
  2791.  
  2792.   PURPOSE  : Updates a single unit.
  2793.   NOTES    : Updates also frozen Units.
  2794.  
  2795.   RETURNS  : Returns error code if unit doesn't exist, 0 otherwise.
  2796.   UPDATE   : 
  2797. ******************************************************************************/
  2798. krui_err   krui_updateSingleUnit(int unit_no)
  2799. {
  2800.   register struct Unit   *unit_ptr;
  2801.  
  2802. #ifdef MASPAR_KERNEL
  2803.   MASPAR_FF1_VALIDATE_OP;
  2804. #endif
  2805.  
  2806.   if ((unit_ptr = kr_getUnitPtr( unit_no )) == NULL)
  2807.     return( KernelErrorCode );
  2808.  
  2809.   if (unit_ptr->out_func == NULL)
  2810.     /*  Identity Function   */
  2811.     unit_ptr->Out.output = unit_ptr->act = (*unit_ptr->act_func) (unit_ptr);
  2812.   else
  2813.     {
  2814.     unit_ptr->act = (*unit_ptr->act_func) (unit_ptr);
  2815.     unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act);
  2816.   }
  2817.  
  2818.   return( KRERR_NO_ERROR );
  2819. }
  2820.  
  2821. /*****************************************************************************
  2822.   FUNCTION : krui_getUpdateFunc
  2823.  
  2824.   PURPOSE  : Returns the current update function. The default update function is
  2825.              SerialOrder() (see also kr_def.h).
  2826.   NOTES    : 
  2827.  
  2828.   RETURNS  : 
  2829.   UPDATE   : 
  2830. ******************************************************************************/
  2831. char  *krui_getUpdateFunc(void)
  2832. {
  2833.   static char  updateFunc[FUNCTION_NAME_MAX_LEN];
  2834.  
  2835.   strcpy( updateFunc, krf_getCurrentNetworkFunc( UPDATE_FUNC ) );
  2836.  
  2837.   return( updateFunc );
  2838. }
  2839.  
  2840. /*****************************************************************************
  2841.   FUNCTION : krui_setUpdateFunc 
  2842.  
  2843.   PURPOSE  : Changes the current update function.
  2844.   NOTES    : 
  2845.  
  2846.   RETURNS  : Returns error code if update function is invalid.
  2847.   UPDATE   : 
  2848. ******************************************************************************/
  2849. krui_err   krui_setUpdateFunc(char *update_func)
  2850. {
  2851.   return( krf_setCurrentNetworkFunc( update_func, UPDATE_FUNC ) );
  2852. }
  2853.  
  2854. /*****************************************************************************
  2855.   FUNCTION : krui_updateNet
  2856.  
  2857.   PURPOSE  : Updates the network according to update function:
  2858.   NOTES    : The network should be feedforward in topological mode,
  2859.              otherwise function will return a warning message.
  2860.  
  2861.              See also krui_setSeedNo for initializing the pseudo
  2862.              random generator.
  2863.  
  2864.   RETURNS  : Returns error code if an error occured, 0 othrwise.
  2865.   UPDATE   : 
  2866. ******************************************************************************/
  2867. krui_err  krui_updateNet(float *parameterInArray, int NoOfInParams)
  2868. {
  2869.   return( kr_callNetworkFunction( UPDATE_FUNC,
  2870.                   parameterInArray, NoOfInParams,
  2871.                   NULL, NULL,
  2872.                   0, 0 ) );
  2873. }
  2874.  
  2875.  
  2876.  
  2877. /*#################################################
  2878.  
  2879. GROUP: Initialisation Functions
  2880.  
  2881. #################################################*/
  2882.  
  2883. /*****************************************************************************
  2884.   FUNCTION : krui_getInitialisationFunc
  2885.  
  2886.   PURPOSE  : 
  2887.   NOTES    : 
  2888.  
  2889.   RETURNS  : Returns the current initialisation function. The default initialisation function is
  2890.     RandomizeWeights (see also kr_def.h).
  2891.   UPDATE   : 
  2892. ******************************************************************************/
  2893. char  *krui_getInitialisationFunc(void)
  2894. {
  2895.   return( krf_getCurrentNetworkFunc( INIT_FUNC ) );
  2896. }
  2897.  
  2898. /*****************************************************************************
  2899.   FUNCTION : krui_setInitialisationFunc
  2900.  
  2901.   PURPOSE  : Changes the current learning function.  Returns error code if learning
  2902.     function is invalid.
  2903.   NOTES    : 
  2904.  
  2905.   RETURNS  : 
  2906.   UPDATE   : 
  2907. ******************************************************************************/
  2908. krui_err   krui_setInitialisationFunc(char *initialisation_func)
  2909. {
  2910.   return( krf_setCurrentNetworkFunc( initialisation_func, INIT_FUNC ) );
  2911. }
  2912. /*****************************************************************************
  2913.   FUNCTION : krui_initializeNet
  2914.  
  2915.   PURPOSE  : Initializes the network
  2916.   NOTES    : 
  2917.  
  2918.   RETURNS  : 
  2919.   UPDATE   : 
  2920. ******************************************************************************/
  2921. krui_err  krui_initializeNet(float *parameterInArray, int NoOfInParams)
  2922. {
  2923.   return( kr_callNetworkFunction( INIT_FUNC,
  2924.                   parameterInArray, NoOfInParams,
  2925.                   NULL, NULL,
  2926.                   0, 0 ) );
  2927. }
  2928.  
  2929.  
  2930. /*#################################################
  2931.  
  2932. GROUP: Learning Functions
  2933.  
  2934. #################################################*/
  2935.  
  2936. /*****************************************************************************
  2937.   FUNCTION : krui_getLearnFunc
  2938.  
  2939.   PURPOSE  : Returns the current learning function. The default learning function is
  2940.              Backpropagation (see also kr_def.h).
  2941.   NOTES    : 
  2942.  
  2943.   RETURNS  : 
  2944.   UPDATE   : 
  2945. ******************************************************************************/
  2946. char  *krui_getLearnFunc(void)
  2947. {
  2948.   static char  learnFunc[FUNCTION_NAME_MAX_LEN];
  2949.  
  2950.   strcpy( learnFunc, krf_getCurrentNetworkFunc( LEARN_FUNC ) );
  2951.  
  2952.   return( learnFunc );
  2953. }
  2954.  
  2955.  
  2956. /*****************************************************************************
  2957.   FUNCTION : krui_setLearnFunc
  2958.  
  2959.   PURPOSE  : hanges the current learning function.
  2960.   NOTES    : 
  2961.  
  2962.   RETURNS  : Returns error code if learning function is invalid 
  2963.   UPDATE   : 
  2964. ******************************************************************************/
  2965. krui_err   krui_setLearnFunc(char *learning_func)
  2966. {
  2967.   return( krf_setCurrentNetworkFunc( learning_func, LEARN_FUNC ) );
  2968. }
  2969.  
  2970. /*****************************************************************************
  2971.   FUNCTION : krui_learnAllPatterns
  2972.  
  2973.   PURPOSE  :  Learn all pattern pairs using current learning method.
  2974.               parameterInArray contains the learning
  2975.               parameter(s). NoOfInParams stores the number of learning parameters.
  2976.               parameterOutArray returns the results from the learning function.
  2977.               this array is a static array defined in the learning function.
  2978.               *NoOfOutParams points to a integer value that contains the number
  2979.               of output parameters from the current learning function.
  2980.   NOTES    :  Patterns must be loaded before calling this function.
  2981.   REMEMBER :  The backpropagation learning function takes the learning
  2982.               parameter from parameterInArray[ 0 ]. parameterOutArray[ 0 ]
  2983.               returns the current net error.
  2984.  
  2985.  
  2986.   RETURNS  : Returns an error code if memory allocation has failed or if
  2987.              the parameters are invalid.
  2988.   UPDATE   : 
  2989. ******************************************************************************/
  2990. krui_err   krui_learnAllPatterns(float *parameterInArray, int NoOfInParams, float **parameterOutArray, int *NoOfOutParams)
  2991. /*  REMEMBER:  parameterOutArray[ 0 ] returns the current net error
  2992.                parameterInArray[ 0 ] contains the 1st learning parameter
  2993. */
  2994.                                                  
  2995.                                   
  2996. {
  2997.   /*  learn all patterns  */
  2998.   return( kr_callNetworkFunction( LEARN_FUNC,
  2999.                   parameterInArray, NoOfInParams,
  3000.                   parameterOutArray, NoOfOutParams,
  3001.                   0, kr_np_pattern( PATTERN_GET_NUMBER, 0, 0 ) - 1 ) );
  3002. }
  3003.  
  3004. /*****************************************************************************
  3005.   FUNCTION : krui_learnSinglePattern
  3006.  
  3007.   PURPOSE  : Same as krui_learnAllPatterns( ... ) but learns only the current
  3008.              pattern pair. 
  3009.   NOTES    : Patterns must be loaded before calling this function.
  3010.  
  3011.   RETURNS  : 
  3012.   UPDATE   : 
  3013. ******************************************************************************/
  3014. krui_err   krui_learnSinglePattern(int pattern_no, float *parameterInArray, int NoOfInParams, float **parameterOutArray, int *NoOfOutParams)
  3015. {
  3016.   KernelErrorCode = KRERR_NO_ERROR;
  3017.   return( kr_callNetworkFunction( LEARN_FUNC,
  3018.                   parameterInArray, NoOfInParams,
  3019.                   parameterOutArray, NoOfOutParams,
  3020.                   pattern_no - 1, pattern_no - 1 ) );
  3021. }
  3022.  
  3023.  
  3024.  
  3025. /*#################################################
  3026.  
  3027. GROUP: Pattern Management
  3028.  
  3029. #################################################*/
  3030. /*****************************************************************************
  3031.   FUNCTION : krui_setPatternNo
  3032.  
  3033.   PURPOSE  : Sets the current pattern.
  3034.   NOTES    : Patterns must be loaded before calling this function.
  3035.  
  3036.   RETURNS  : Returns a error code if pattern number is invalid.
  3037.   UPDATE   : 
  3038. ******************************************************************************/
  3039. krui_err  krui_setPatternNo(int pattern_no)
  3040. {
  3041.   return( kr_np_pattern( PATTERN_SET, 0, pattern_no ) );
  3042. }
  3043. /*****************************************************************************
  3044.   FUNCTION : krui_deletePattern
  3045.  
  3046.   PURPOSE  :delete the current pattern pair 
  3047.   NOTES    : 
  3048.  
  3049.   RETURNS  : 
  3050.   UPDATE   : 
  3051. ******************************************************************************/
  3052. krui_err  krui_deletePattern(void)
  3053. {
  3054.   return( kr_np_pattern( PATTERN_DELETE, 0 , 0 ) );
  3055. }
  3056.  
  3057. /*****************************************************************************
  3058.   FUNCTION : krui_modifyPattern 
  3059.  
  3060.   PURPOSE  : modify the current pattern pair 
  3061.   NOTES    : 
  3062.  
  3063.   RETURNS  : 
  3064.   UPDATE   : 
  3065. ******************************************************************************/
  3066. krui_err  krui_modifyPattern(void)
  3067. {
  3068.   return( kr_np_pattern( PATTERN_MODIFY, 0 , 0 ) );
  3069. }
  3070.  
  3071. /*****************************************************************************
  3072.   FUNCTION : krui_showPattern
  3073.  
  3074.   PURPOSE  : According to the mode krui_showPattern stores the current
  3075.              Pattern into the units activation (and/or output) values.
  3076.              The modes are:
  3077.                - OUTPUT_NOTHING
  3078.                   store input pattern into input units activations
  3079.                - OUTPUT_ACT
  3080.                   store input pattern into input units activations and
  3081.                   store output pattern into output units activations
  3082.                - OUTPUT_OUT
  3083.                   store input pattern into input units activations,
  3084.                   store output pattern into output units activations and
  3085.                   update output units output
  3086.  
  3087.   NOTES    : See include file glob_typ.h for mode constants.
  3088.  
  3089.   RETURNS  : 
  3090.   UPDATE   : 
  3091. ******************************************************************************/
  3092. krui_err  krui_showPattern(int mode)
  3093. {
  3094.   return( kr_np_pattern( PATTERN_SHOW, mode, 0 ) );
  3095. }
  3096.  
  3097. /*****************************************************************************
  3098.   FUNCTION : krui_allocNewPatternSet
  3099.  
  3100.   PURPOSE  : Allocate a new empty pattern set
  3101.   NOTES    : 
  3102.  
  3103.   RETURNS  : Returns the number of the allcated pattern set;
  3104.              Returns error code if an error occured 
  3105.   UPDATE   : 
  3106. ******************************************************************************/
  3107. krui_err  krui_allocNewPatternSet(int *set_no)
  3108. {
  3109.     KernelErrorCode = kr_npui_allocNewPatternSet(set_no);
  3110.     return KernelErrorCode;
  3111. }
  3112.  
  3113. /*****************************************************************************
  3114.   FUNCTION : krui_newPattern
  3115.  
  3116.   PURPOSE  : Creates a new pattern pair.
  3117.              A pattern pair can be created by modifying the activation
  3118.              value of the input/output units.
  3119.   NOTES    : krui_newPattern switches pattern shuffeling off.
  3120.              For shuffeling the new pattern pairs call
  3121.                  krui_newPattern(...)
  3122.                  krui_shufflePattern( TRUE )
  3123.  
  3124.   RETURNS  : Returns error code if memory is insufficent or no. of
  3125.              input/output units is incompatible, 0 otherwise.
  3126.   UPDATE   : 
  3127. ******************************************************************************/
  3128. krui_err  krui_newPattern(void)
  3129. {
  3130.   return( kr_np_pattern( PATTERN_NEW, 0, 0 ) );
  3131. }
  3132.  
  3133. /*****************************************************************************
  3134.   FUNCTION : krui_getNoOfPatterns
  3135.  
  3136.   PURPOSE  : Returns the no. of available pattern pairs.
  3137.   NOTES    : 
  3138.  
  3139.   RETURNS  : 
  3140.   UPDATE   : 
  3141. ******************************************************************************/
  3142. int  krui_getNoOfPatterns(void)
  3143. {
  3144.   return( kr_np_pattern( PATTERN_GET_NUMBER, 0, 0 ) );
  3145. }
  3146.  
  3147.  
  3148. /*****************************************************************************
  3149.   FUNCTION : krui_deleteAllPatterns
  3150.  
  3151.   PURPOSE  : [ Release previously defined patterns from memory.
  3152.                Call krui_releasePatterns() if you want to create totally
  3153.                new patterns with krui_newPattern(). ]
  3154.   NOTES    : This function is of no effect any longer since there exists 
  3155.              the new function krui_deletePatSet (see below)
  3156.  
  3157.   RETURNS  : 
  3158.   UPDATE   : 
  3159. ******************************************************************************/
  3160. void  krui_deleteAllPatterns(void)
  3161. {
  3162.   (void) kr_np_pattern( PATTERN_DELETE_ALL, 0, 0 );
  3163. }
  3164.  
  3165. /*****************************************************************************
  3166.   FUNCTION : krui_shufflePatterns
  3167.  
  3168.   PURPOSE  : Shuffle pattern pairs by using pseudo random generator.
  3169.              Shuffeling of patterns is used by krui_learnAllPatterns(...).
  3170.              krui_shufflePatterns( TRUE ) switches shuffeling of patterns
  3171.              on, krui_shufflePatterns( FALSE ) switches shuffeling of
  3172.              patterns off.
  3173.              The default presetting is krui_shufflePatterns( FALSE ). 
  3174.   NOTES    : See also krui_setSeedNo( seed )
  3175.  
  3176.   RETURNS  : 
  3177.   UPDATE   : 
  3178. ******************************************************************************/
  3179. krui_err  krui_shufflePatterns(bool on_or_off)
  3180. {
  3181.     if (on_or_off)
  3182.     return kr_np_pattern( PATTERN_SHUFFLE_ON, 0, 0 );
  3183.     else
  3184.     return kr_np_pattern( PATTERN_SHUFFLE_OFF, 0, 0 );
  3185. }
  3186.  
  3187. /*****************************************************************************
  3188.   FUNCTION : krui_shuffleSubPatterns
  3189.  
  3190.   PURPOSE  : Shuffle sub pattern pairs by using pseudo random generator.
  3191.              Shuffeling of patterns is used by krui_learnAllPatterns(...).
  3192.              krui_shuffleSubPatterns(TRUE) switches shuffeling of sub patterns
  3193.              on, krui_shuffleSubPatterns( FALSE ) switches shuffeling of
  3194.              sub patterns off.
  3195.              The default presetting is krui_shuffleSubPatterns( FALSE ). 
  3196.   NOTES    : See also krui_setSeedNo( seed )
  3197.  
  3198.   RETURNS  : 
  3199.   UPDATE   : 
  3200. ******************************************************************************/
  3201. krui_err  krui_shuffleSubPatterns(bool on_or_off)
  3202. {
  3203.     if (on_or_off)
  3204.     return kr_np_pattern( PATTERN_SUB_SHUFFLE_ON, 0, 0 );
  3205.     else
  3206.     return kr_np_pattern( PATTERN_SUB_SHUFFLE_OFF, 0, 0 );
  3207. }
  3208.  
  3209. /*****************************************************************************
  3210.   FUNCTION : krui_setCurrPatSet
  3211.  
  3212.   PURPOSE  : Choose the number of the current pattern set.
  3213.              <number> starts from 0.
  3214.   RETURNS  : 
  3215.   NOTES    :
  3216.  
  3217.   UPDATE   : 
  3218. ******************************************************************************/
  3219. krui_err  krui_setCurrPatSet(int number)
  3220. {
  3221.     return kr_npui_setCurrPatSet(number);
  3222. }
  3223.  
  3224. /*****************************************************************************
  3225.   FUNCTION : krui_deletePatSet
  3226.  
  3227.   PURPOSE  : Delete all patterns of pattern set with number <number>
  3228.              The ordering of the remaining pattern sets is reorganized by
  3229.          decrementing the pattern set numbers which are higher than 
  3230.          <number> by 1. For example: there exist the pattern sets 0, 1, 2 
  3231.          and 3. After deleting pattern set 1 the pattern sets 2 and 3 are 
  3232.          renamed to 1 and 2.
  3233.   RETURNS  : 
  3234.   NOTES    :
  3235.  
  3236.   UPDATE   : 
  3237. ******************************************************************************/
  3238. krui_err  krui_deletePatSet(int number)
  3239. {
  3240.     return kr_npui_deletePatSet(number);
  3241. }
  3242.  
  3243. /*****************************************************************************
  3244.   FUNCTION : krui_GetPatInfo
  3245.  
  3246.   PURPOSE  : Get all available information concerning the current pattern set
  3247.              and the current pattern.
  3248.   RETURNS  : 
  3249.   NOTES    :
  3250.  
  3251.   UPDATE   : 
  3252. ******************************************************************************/
  3253. krui_err  krui_GetPatInfo(pattern_set_info *set_info, 
  3254.                           pattern_descriptor *pat_info)
  3255. {
  3256.     return kr_npui_GetPatInfo(set_info, pat_info);
  3257. }
  3258.  
  3259. /*****************************************************************************
  3260.   FUNCTION : krui_DefShowSubPat
  3261.  
  3262.   PURPOSE  : Define the sub pattern to be shown with next call to 
  3263.              krui_showPattern 
  3264.   RETURNS  : 
  3265.   NOTES    :
  3266.  
  3267.   UPDATE   : 
  3268. ******************************************************************************/
  3269. krui_err  krui_DefShowSubPat(int *insize, int *outsize, 
  3270.                  int *inpos, int *outpos)
  3271. {
  3272.     return kr_npui_DefShowSubPat(insize, outsize, inpos, outpos);
  3273. }
  3274.  
  3275. /*****************************************************************************
  3276.   FUNCTION : krui_DefTrainSubPat
  3277.  
  3278.   PURPOSE  : Define how sub patterns should be generated during training
  3279.   RETURNS  : 
  3280.   NOTES    :
  3281.  
  3282.   UPDATE   : 
  3283. ******************************************************************************/
  3284. krui_err  krui_DefTrainSubPat(int *insize, int *outsize,
  3285.                   int *instep, int *outstep, int *max_n_pos)
  3286. {
  3287.     return kr_npui_DefTrainSubPat(insize, outsize, instep, outstep, max_n_pos);
  3288. }
  3289.  
  3290. /*****************************************************************************
  3291.   FUNCTION : krui_AlignSubPat
  3292.  
  3293.   PURPOSE  : Align the given sub pattern position (<inpos> and <outpos>)
  3294.              to a valid position which fits the defined sub pattern training 
  3295.          scheme (krui_DefTrainSubPat).
  3296.  
  3297.   RETURNS  : kernel error code
  3298.              <inpos> and <outpos> returns the aligned position
  3299.              <no> returns the resulting ordering position of the sub pattern
  3300.   NOTES    :
  3301.  
  3302.   UPDATE   : 
  3303. ******************************************************************************/
  3304. krui_err krui_AlignSubPat(int *inpos, int *outpos, int *no)
  3305. {
  3306.     return kr_npui_AlignSubPat(inpos, outpos, no);
  3307. }
  3308.  
  3309. /*****************************************************************************
  3310.   FUNCTION : krui_GetShapeOfSubPattern
  3311.  
  3312.   PURPOSE  : Get shape of sub pattern <n_pos> using current set,
  3313.              current pattern and current train scheme (defined with
  3314.          krui_DefTrainSubPat)
  3315.   RETURNS  : 
  3316.   NOTES    :
  3317.  
  3318.   UPDATE   : 
  3319. ******************************************************************************/
  3320. krui_err  krui_GetShapeOfSubPattern(int *insize, int *outsize, 
  3321.                     int *inpos, int *outpos, int n_pos)
  3322. {
  3323.     return kr_npui_GetShapeOfSubPat(insize, outsize, inpos, outpos, n_pos);
  3324. }
  3325.  
  3326. /*#################################################
  3327.  
  3328. GROUP: I/O Functions
  3329.  
  3330. #################################################*/
  3331. /*****************************************************************************
  3332.   FUNCTION : krui_saveNet
  3333.  
  3334.   PURPOSE  : Save a network.
  3335.              If netname is a NULL pointer, the net will get the name "UNTITLED"
  3336.   NOTES    : 
  3337.  
  3338.   RETURNS  :  Returns error code if an error occured, or 0 otherwise.
  3339.   UPDATE   : 
  3340. ******************************************************************************/
  3341. krui_err  krui_saveNet(char *filename, char *netname)
  3342. {
  3343.   return( krio_saveNet( filename, netname ) );
  3344. }
  3345.  
  3346. /*****************************************************************************
  3347.   FUNCTION : krui_loadNet
  3348.  
  3349.   PURPOSE  : Load a network file and create a network.
  3350.              Returns the name of the net or "UNTITLED" if unknown.
  3351.   NOTES    : 
  3352.  
  3353.   RETURNS  : Returns error code if an error occured during
  3354.              loading/memory allocation, or 0 otherwise. 
  3355.   UPDATE   : 
  3356. ******************************************************************************/
  3357. krui_err  krui_loadNet(char *filename, char **netname)
  3358. {
  3359.   char    *netfile_version;  /*  isn't used now  */
  3360.               
  3361.   KernelErrorCode = KRERR_NO_ERROR;
  3362.  
  3363.   KernelErrorCode = krio_loadNet( filename, netname, &netfile_version );
  3364.   if (KernelErrorCode != KRERR_NO_ERROR)
  3365.     return( KernelErrorCode );
  3366.  
  3367.   kr_updateUnitOutputs();
  3368.  
  3369.   /*
  3370.   if (kr_np_pattern( PATTERN_GET_NUMBER, 0, 0 ) > 0)
  3371.     KernelErrorCode = kr_IOCheck();
  3372.   */
  3373.  
  3374.   return( KernelErrorCode );
  3375. }
  3376.  
  3377. /*****************************************************************************
  3378.   FUNCTION : krui_loadNewPatterns
  3379.  
  3380.   PURPOSE  : Load file containing pattern pairs of new Style conventions.
  3381.   NOTES    : 
  3382.  
  3383.   RETURNS  : Returns the number of the loaded pattern set;
  3384.              Returns error code if an error occured during
  3385.              loading/memory allocation, or 0 otherwise.
  3386.   UPDATE   : 
  3387. ******************************************************************************/
  3388. krui_err  krui_loadNewPatterns(char *filename, int *set_no)
  3389. {
  3390.     KernelErrorCode = kr_npui_loadNewPatterns(filename, set_no);
  3391.     return KernelErrorCode;
  3392. }
  3393.  
  3394. /*****************************************************************************
  3395.   FUNCTION : krui_saveNewPatterns
  3396.  
  3397.   PURPOSE  : Save pattern file with new style conventions
  3398.              The pattern set with number <number> is saved.
  3399.   NOTES    : 
  3400.  
  3401.   RETURNS  : 
  3402.   UPDATE   : 
  3403. ******************************************************************************/
  3404. krui_err  krui_saveNewPatterns(char *filename, int set_no)
  3405. {
  3406.     KernelErrorCode = kr_npui_saveNewPatterns(filename, set_no);
  3407.     return KernelErrorCode;
  3408. }
  3409.  
  3410. /*****************************************************************************
  3411.   FUNCTION : krui_saveResult
  3412.  
  3413.   PURPOSE  : Save the network result which depends on the loaded patterns.
  3414.              If create is false, the new file will be appended to an existing file.
  3415.              startpattern and endpattern determine the range of patterns to use.
  3416.              The input patterns and the teaching output patterns can be included.
  3417.   NOTES    : 
  3418.  
  3419.   RETURNS  : 
  3420.   UPDATE   : 
  3421. ******************************************************************************/
  3422. krui_err  krui_saveResult(char *filename, bool create, int startpattern, int endpattern, bool includeinput, bool includeoutput)
  3423. {
  3424.   return( krio_saveResult(filename, create, startpattern, endpattern,
  3425.     includeinput, includeoutput));
  3426. }
  3427.  
  3428.  
  3429.  
  3430. /*#################################################
  3431.  
  3432. GROUP: Functions for memory management
  3433.  
  3434. #################################################*/
  3435. /*****************************************************************************
  3436.   FUNCTION : krui_allocateUnits
  3437.  
  3438.   PURPOSE  : Allocates a given number of units, additional units
  3439.              may allocated by calling this function again.
  3440.              This function is called automatically if the user
  3441.              construct more units than have been allocated before, but
  3442.              it is recommended to use this function if a large amount
  3443.              of units is needed (the UNIX System can manage system resources
  3444.              much better, if the amount of memory used for the network is
  3445.              approximately known before the network is created).
  3446.   NOTES    : If krui_create_unit has been called before using this
  3447.              function, at least <UNIT_BLOCK> numbers of units have been
  3448.              allocated.
  3449.              See "kr_def.h" for more information about memory allocation
  3450.              block sizes.
  3451.  
  3452.   RETURNS  : Returns error code if memory allocation fails, 0 otherwise.
  3453.   UPDATE   : 
  3454. ******************************************************************************/
  3455. krui_err  krui_allocateUnits(int no_of_units)
  3456. {
  3457.   return( krm_allocUnits( no_of_units ) );
  3458. }
  3459.  
  3460. /*****************************************************************************
  3461.   FUNCTION : krui_deleteNet
  3462.  
  3463.   PURPOSE  :  Delete network, names and unit types.
  3464.               Frees all memory used for the network.
  3465.   NOTES    : If krui_loadNet is called more then once,  krui_deleteNet will
  3466.              be called by krui_loadNet, because the kernel have to free the
  3467.              memory used for the old network.
  3468.              It is recommended (but not neccessary) to call krui_deleteNet
  3469.              before terminating the SNNS-Kernel.
  3470.  
  3471.   RETURNS  : 
  3472.   UPDATE   : 
  3473. ******************************************************************************/
  3474. void  krui_deleteNet(void)
  3475. {
  3476.   krm_releaseMem();
  3477. }
  3478.  
  3479.  
  3480. /*#################################################
  3481.  
  3482. GROUP: Functions for reading/searching the symbol table
  3483.  
  3484. #################################################*/
  3485. /*****************************************************************************
  3486.   FUNCTION : krui_getFirstSymbolTableEntry
  3487.  
  3488.   PURPOSE  : Returns the first symbol/symbol type entry in the
  3489.              symbol table. Returns true if this entry is available,
  3490.              false otherwise. 
  3491.   NOTES    : 
  3492.  
  3493.   RETURNS  : 
  3494.   UPDATE   : 
  3495. ******************************************************************************/
  3496. bool  krui_getFirstSymbolTableEntry(char **symbol_name, int *symbol_type)
  3497. {
  3498.   struct NameTable      *n_tbl;
  3499.  
  3500.  
  3501.   n_tbl = krm_getNTableFirstEntry();
  3502.  
  3503.   while ( (n_tbl != NULL) && ((int) n_tbl->sym_type == UNUSED_SYM) )
  3504.     n_tbl = krm_getNTableNextEntry();
  3505.  
  3506.   if (n_tbl == NULL)
  3507.     {
  3508.     *symbol_name = NULL;
  3509.     *symbol_type = 0;
  3510.     return( FALSE );
  3511.     }
  3512.  
  3513.   *symbol_name = n_tbl->Entry.symbol;
  3514.   *symbol_type = (int) n_tbl->sym_type;
  3515.   return( TRUE );
  3516. }
  3517.  
  3518.  
  3519. /*****************************************************************************
  3520.   FUNCTION : krui_getNextSymbolTableEntry
  3521.  
  3522.   PURPOSE  : Returns the next symbol/symbol type entry in the
  3523.              symbol table. Returns true if another entry is available,
  3524.              false otherwise.
  3525.   NOTES    : 
  3526.  
  3527.   RETURNS  : 
  3528.   UPDATE   : 
  3529. ******************************************************************************/
  3530. bool  krui_getNextSymbolTableEntry(char **symbol_name, int *symbol_type)
  3531. {
  3532.   struct NameTable      *n_tbl;
  3533.  
  3534.  
  3535.   n_tbl = krm_getNTableNextEntry();
  3536.  
  3537.   while ( (n_tbl != NULL) && ((int) n_tbl->sym_type == UNUSED_SYM) )
  3538.     n_tbl = krm_getNTableNextEntry();
  3539.  
  3540.   if (n_tbl == NULL)
  3541.     {
  3542.     *symbol_name = NULL;
  3543.     *symbol_type = 0;
  3544.     return( FALSE );
  3545.     }
  3546.  
  3547.   *symbol_name = n_tbl->Entry.symbol;
  3548.   *symbol_type = (int) n_tbl->sym_type;
  3549.   return( TRUE );
  3550. }
  3551.  
  3552.  
  3553.  
  3554.  
  3555. /*****************************************************************************
  3556.   FUNCTION : krui_symbolSearch
  3557.  
  3558.   PURPOSE  : Searches the symbol table for a given symbol and
  3559.              symbol type (unit name symbol, site name symbol,
  3560.              functionality unit name symbol)
  3561.   NOTES    : 
  3562.  
  3563.   RETURNS  : Returns true, if the symbol exists.
  3564.   UPDATE   : 
  3565. ******************************************************************************/
  3566. bool  krui_symbolSearch(char *symbol, int symbol_type)
  3567. {
  3568.   return( krm_NTableSymbolSearch( symbol, symbol_type ) != NULL );
  3569. }
  3570.  
  3571.  
  3572.  
  3573.  
  3574.  
  3575.  
  3576. /*#################################################
  3577.  
  3578. GROUP: Miscellanous
  3579.  
  3580. #################################################*/
  3581.  
  3582. /*****************************************************************************
  3583.   FUNCTION : krui_getVersion
  3584.  
  3585.   PURPOSE  : Returns the current Version of the SNNS-Kernel.
  3586.   NOTES    : 
  3587.  
  3588.   RETURNS  : 
  3589.   UPDATE   : 
  3590. ******************************************************************************/
  3591. char  *krui_getVersion(void)
  3592. {
  3593.   static char    snns_version[128];
  3594.  
  3595.  
  3596.   strcpy( snns_version, SNNS_VERSION );
  3597.   strcat( snns_version, KERNEL_PATCH );
  3598.   return( snns_version );
  3599. }
  3600.  
  3601. /*****************************************************************************
  3602.   FUNCTION : krui_getNetInfo
  3603.  
  3604.   PURPOSE  : Returns miscellanous information about the current network.
  3605.   NOTES    : 
  3606.  
  3607.   RETURNS  : 
  3608.   UPDATE   : 
  3609. ******************************************************************************/
  3610. void  krui_getNetInfo(int *no_of_sites, int *no_of_links, int *no_of_STable_entries, int *no_of_FTable_entries)
  3611. {
  3612.   int   array_size,
  3613.         info_array[ 10 ];
  3614.  
  3615.  
  3616.   krm_getMemoryManagerInfo( &array_size, info_array );
  3617.  
  3618.   *no_of_sites          = info_array[ 0 ];
  3619.   *no_of_links          = info_array[ 1 ];
  3620.   *no_of_STable_entries = info_array[ 2 ];
  3621.   *no_of_FTable_entries = info_array[ 3 ];
  3622. }
  3623.  
  3624. /*****************************************************************************
  3625.   FUNCTION : krui_getMemoryManagerInfo
  3626.  
  3627.   PURPOSE  : Returns the number of ALLOCATED (not the number of USED) bytes
  3628.     per entry.
  3629.   NOTES    : 
  3630.  
  3631.   RETURNS  : 
  3632.   UPDATE   : 
  3633. ******************************************************************************/
  3634. void  krui_getMemoryManagerInfo(int *unit_bytes, int *site_bytes, int *link_bytes, int *NTable_bytes, int *STable_bytes, int *FTable_bytes)
  3635. {
  3636.   int   array_size,
  3637.         info_array[ 10 ];
  3638.  
  3639.  
  3640.   krm_getMemoryManagerInfo( &array_size, info_array );
  3641.  
  3642.   *unit_bytes   = info_array[ 4 ] * UNIT_SIZE;
  3643.   *site_bytes   = info_array[ 5 ] * SITE_SIZE;
  3644.   *link_bytes   = info_array[ 6 ] * LINK_SIZE;
  3645.   *NTable_bytes = info_array[ 7 ] * NTABLE_SIZE;
  3646.   *STable_bytes = info_array[ 8 ] * STABLE_SIZE;
  3647.   *FTable_bytes = info_array[ 9 ] * FTYPE_UNIT_SIZE;
  3648. }
  3649.  
  3650. /*****************************************************************************
  3651.   FUNCTION : krui_getUnitDefaults
  3652.  
  3653.   PURPOSE  : Returns Information about the unit default settings.
  3654.              For more information about default settings see krui_createDefaultUnit() and
  3655.               krui_createFTypeUnit( .. ).
  3656.   NOTES    : 
  3657.  
  3658.   RETURNS  : 
  3659.   UPDATE   : 
  3660. ******************************************************************************/
  3661. void  krui_getUnitDefaults(FlintType *act, FlintType *bias, int *st, int *subnet_no, int *layer_no, char **act_func, char **out_func)
  3662. {
  3663.   int    ttflags;
  3664.  
  3665.   kr_getUnitDefaults( act, bias, &ttflags, subnet_no, layer_no,
  3666.               act_func, out_func );
  3667.  
  3668.   *st = kr_flags2TType( ttflags );
  3669. }
  3670.  
  3671. /*****************************************************************************
  3672.   FUNCTION :  krui_setUnitDefaults
  3673.  
  3674.   PURPOSE  : Changes the unit default settings.
  3675.              For more information about default settings see krui_createDefaultUnit() and
  3676.              krui_createFTypeUnit( .. ).
  3677.   NOTES    : 
  3678.  
  3679.   RETURNS  : Returns error code if
  3680.              - activation/output function is invalid
  3681.              - Topologic type is invalid
  3682.              0 otherwise.
  3683.   UPDATE   : 
  3684. ******************************************************************************/
  3685. krui_err  krui_setUnitDefaults(FlintTypeParam act, FlintTypeParam bias, int st, int subnet_no, int layer_no, char *act_func, char *out_func)
  3686. {
  3687.   int           ttflags;
  3688.  
  3689.   ttflags = kr_TType2Flags( st );
  3690.   if (KernelErrorCode != KRERR_NO_ERROR)
  3691.     return( KernelErrorCode );
  3692.  
  3693.   kr_setUnitDefaults( act, bias, ttflags, subnet_no, layer_no,
  3694.               act_func, out_func );
  3695.   return( KernelErrorCode );
  3696. }
  3697.  
  3698. /*****************************************************************************
  3699.   FUNCTION : krui_resetNet
  3700.  
  3701.   PURPOSE  : Reset the network by changeing the unit activation
  3702.              to the initial activation value.
  3703.   NOTES    : 
  3704.  
  3705.   RETURNS  : 
  3706.   UPDATE   : 
  3707. ******************************************************************************/
  3708. void  krui_resetNet(void)
  3709. {
  3710.   register int   i;
  3711.   register struct Unit   *unit_ptr;
  3712.  
  3713.  
  3714.   if ( (unit_array == NULL) || (NoOfUnits == 0) )
  3715.     return;
  3716.  
  3717.  
  3718.   for (i = MinUnitNo, unit_ptr = unit_array + MinUnitNo; i <= MaxUnitNo; i++, unit_ptr++)
  3719.     if UNIT_IN_USE( unit_ptr )  {
  3720.       /*  unit is in use  */
  3721.       unit_ptr->act = unit_ptr->i_act;
  3722.  
  3723.       if (unit_ptr->out_func == OUT_IDENTITY)
  3724.     /*  identity output function: there is no need to call the output function  */
  3725.     unit_ptr->Out.output = unit_ptr->act;
  3726.       else
  3727.     /*  no identity output function: calculate unit's output also  */
  3728.     unit_ptr->Out.output = (*unit_ptr->out_func) (unit_ptr->act);
  3729.     }
  3730. }
  3731. /*****************************************************************************
  3732.   FUNCTION : krui_setSeedNo
  3733.  
  3734.   PURPOSE  : Initialize the pseudo random generator.
  3735.              0 as argument reinitializes the random generator.
  3736.   NOTES    : 
  3737.  
  3738.   RETURNS  : 
  3739.   UPDATE   : 
  3740. ******************************************************************************/
  3741. void  krui_setSeedNo(long int seed)
  3742. {
  3743.   if (seed != 0)
  3744.     srand48( seed );   /*  initialize random generator with seed value    */
  3745.   else
  3746.     srand48( (long) time( (time_t *) 0) );  /*  initialize random generator random value    */
  3747. }
  3748.  
  3749. /*****************************************************************************
  3750.   FUNCTION : krui_getNoOfInputUnits
  3751.  
  3752.   PURPOSE  : 
  3753.   NOTES    : 
  3754.  
  3755.   RETURNS  : Returns the no. of input units
  3756.   UPDATE   : 
  3757. ******************************************************************************/
  3758. int  krui_getNoOfInputUnits(void)
  3759. {
  3760.   return( kr_getNoOfUnits( INPUT ) + kr_getNoOfUnits( DUAL ) );
  3761. }
  3762. /*****************************************************************************
  3763.   FUNCTION : krui_getNoOfOutputUnits 
  3764.  
  3765.   PURPOSE  : 
  3766.   NOTES    : 
  3767.  
  3768.   RETURNS  : returns the no. of output units
  3769.   UPDATE   : 
  3770. ******************************************************************************/
  3771. int  krui_getNoOfOutputUnits(void)
  3772. {
  3773.   return( kr_getNoOfUnits( OUTPUT ) + kr_getNoOfUnits( DUAL ) );
  3774. }
  3775. /*****************************************************************************
  3776.   FUNCTION : krui_getNoOfTTypeUnits
  3777.  
  3778.   PURPOSE  : returns the no. of units of the specified topologic type
  3779.              (i.e. Input, Hidden, Output or Special units)
  3780.   NOTES    : 
  3781.  
  3782.   RETURNS  : 
  3783.   UPDATE   : 
  3784. ******************************************************************************/
  3785. int  krui_getNoOfTTypeUnits(int UnitTType)
  3786. {
  3787.   return( kr_getNoOfUnits( UnitTType ) );
  3788. }
  3789.  
  3790.  
  3791.  
  3792. #ifdef KERNEL3D
  3793. /*****************************************************************************
  3794.   FUNCTION : krui_xyTransTable
  3795.  
  3796.   PURPOSE  : Get/modify the XY-Translation Table
  3797.   NOTES    : 
  3798.  
  3799.   RETURNS  : 
  3800.   UPDATE   : 
  3801. ******************************************************************************/
  3802. krui_err  krui_xyTransTable(int op, int *x, int *y, int z)
  3803. {
  3804.   return(kr_xyTransTable(op, x, y, z));
  3805.  
  3806. /*****************************************************************************
  3807.   FUNCTION : krui_getUnitCenters
  3808.  
  3809.   PURPOSE  : Returns the 3D transform center of the specified unit and center number
  3810.   NOTES    : 
  3811.  
  3812.   RETURNS  : 
  3813.   UPDATE   : 
  3814. ******************************************************************************/
  3815. krui_err  krui_getUnitCenters(int unit_no, int center_no, struct PositionVector **unit_center)
  3816. {
  3817.   struct Unit   *unit_ptr;
  3818.  
  3819.   KernelErrorCode = KRERR_NO_ERROR;
  3820.  
  3821.   if ((unit_ptr = kr_getUnitPtr( unit_no )) == NULL)
  3822.     return( KernelErrorCode );
  3823.  
  3824.   if ((center_no < 0) || (center_no >= NO_OF_UNIT_CENTER_POS))  {
  3825.     KernelErrorCode = KRERR_PARAMETERS;
  3826.     return( KRERR_PARAMETERS );
  3827.   }
  3828.  
  3829.   *unit_center = unit_ptr->unit_center_pos + center_no;
  3830.   return( KRERR_NO_ERROR );
  3831. }
  3832.  
  3833. /*****************************************************************************
  3834.   FUNCTION :  krui_setUnitCenters
  3835.  
  3836.   PURPOSE  : Sets the 3D transform center of the specified unit and center number
  3837.   NOTES    : 
  3838.  
  3839.   RETURNS  : 
  3840.   UPDATE   : 
  3841. ******************************************************************************/
  3842. krui_err  krui_setUnitCenters(int unit_no, int center_no, struct PositionVector *unit_center)
  3843.   struct Unit   *unit_ptr;
  3844.   struct PositionVector    *unit_posvec_ptr;
  3845.  
  3846.  
  3847.   KernelErrorCode = KRERR_NO_ERROR;
  3848.  
  3849.   if ((unit_ptr = kr_getUnitPtr( unit_no )) == NULL)
  3850.     return( KernelErrorCode );
  3851.  
  3852.   if ((center_no < 0) || (center_no >= NO_OF_UNIT_CENTER_POS))  {
  3853.     KernelErrorCode = KRERR_PARAMETERS;
  3854.     return( KRERR_PARAMETERS );
  3855.   }
  3856.  
  3857.   unit_posvec_ptr = unit_ptr->unit_center_pos + center_no;
  3858.  
  3859.   memcpy( (char *) unit_posvec_ptr, (char *) unit_center, sizeof( struct PositionVector ) );
  3860.  
  3861.   return( KRERR_NO_ERROR );
  3862. }
  3863.  
  3864.  
  3865. #else
  3866.  
  3867. /*****************************************************************************
  3868.   FUNCTION : 
  3869.  
  3870.   PURPOSE  : 
  3871.   NOTES    : 
  3872.  
  3873.   RETURNS  : 
  3874.   UPDATE   : 
  3875. ******************************************************************************/
  3876. /*
  3877. krui_err  krui_getXYTransTable( dummy )
  3878. int dummy;
  3879. {
  3880.   KernelErrorCode = KRERR_NOT_3D;
  3881.  
  3882.   return( KRERR_NOT_3D );
  3883. }
  3884. */
  3885. /*****************************************************************************
  3886.   FUNCTION : 
  3887.  
  3888.   PURPOSE  : 
  3889.   NOTES    : 
  3890.  
  3891.   RETURNS  : 
  3892.   UPDATE   : 
  3893. ******************************************************************************/
  3894. /*
  3895.  
  3896. krui_err  krui_getUnitCenters( unit_no, center_no, dummy )
  3897. int  unit_no, center_no, dummy;
  3898.   KernelErrorCode = KRERR_NOT_3D;
  3899.  
  3900.   return( KRERR_NOT_3D );
  3901. }
  3902. */
  3903.  
  3904. /*****************************************************************************
  3905.   FUNCTION : 
  3906.  
  3907.   PURPOSE  : 
  3908.   NOTES    : 
  3909.  
  3910.   RETURNS  : 
  3911.   UPDATE   : 
  3912. ******************************************************************************/
  3913. /*
  3914.  
  3915. krui_err  krui_setUnitCenters( unit_no, center_no, dummy )
  3916. int  unit_no, center_no, dummy;
  3917.   KernelErrorCode = KRERR_NOT_3D;
  3918.  
  3919.   return( KRERR_NOT_3D );
  3920. }
  3921. */
  3922.  
  3923. #endif
  3924.  
  3925.  
  3926. /*****************************************************************************
  3927.   FUNCTION : 
  3928.  
  3929.   PURPOSE  : 
  3930.   NOTES    : 
  3931.  
  3932.   RETURNS  : 
  3933.   UPDATE   : 
  3934. ******************************************************************************/
  3935.  
  3936. static char  *krui_topo_err_msg(void)
  3937. {
  3938.   char  *dest_unit_name,  *src_unit_name;
  3939.   char  msg1[512], msg2[512];
  3940.  
  3941.  
  3942.   if (topo_msg.dest_error_unit > 0)
  3943.     dest_unit_name = krui_getUnitName( topo_msg.dest_error_unit );
  3944.  
  3945.   if (topo_msg.src_error_unit > 0)
  3946.     src_unit_name = krui_getUnitName( topo_msg.src_error_unit );
  3947.  
  3948.   if (topo_msg.dest_error_unit > 0)
  3949.     if (dest_unit_name == NULL)
  3950.       sprintf( msg1, "Unit #%d is the destination unit. ", topo_msg.dest_error_unit );
  3951.     else
  3952.       sprintf( msg1, "Unit #%d (%s) is the destination unit. ", topo_msg.dest_error_unit,
  3953.                dest_unit_name );
  3954.  
  3955.   if (topo_msg.src_error_unit > 0)
  3956.     if (src_unit_name == NULL)
  3957.       sprintf( msg2, "Unit #%d is the source unit. ", topo_msg.src_error_unit );
  3958.     else
  3959.       sprintf( msg2, "Unit #%d (%s) is the source unit. ", topo_msg.src_error_unit,
  3960.                src_unit_name );
  3961.  
  3962.   if (topo_msg.dest_error_unit == 0)
  3963.     return( msg2 );
  3964.  
  3965.   if (topo_msg.src_error_unit > 0)
  3966.     strcat( msg1, msg2 );
  3967.  
  3968.   return( msg1 );
  3969. }
  3970.  
  3971.  
  3972. /*****************************************************************************
  3973.   FUNCTION : krui_error
  3974.  
  3975.   PURPOSE  : Returns an error message, depending on the error code.
  3976.              If a function returns an error code use krui_error to
  3977.              get the message.
  3978.   NOTES    : 
  3979.  
  3980.   RETURNS  : 
  3981.   UPDATE   : 
  3982. ******************************************************************************/
  3983. char  *krui_error(int error_code)
  3984. {
  3985.   static char    *err_message[] = {
  3986.       "Invalid error code",
  3987.       "Insufficient memory",
  3988.       "Invalid unit number",
  3989.       "Invalid unit output function",
  3990.       "Invalid unit activation function",
  3991.       "Invalid site function",
  3992.       "Creation of sites isn't permitted because unit has direct input links",
  3993.       "Creation of a link isn't permitted because there exists already a link between these units",
  3994.       "Memory allocation failed during critical operation. Have lost some pointers, but consistency of the network is guaranteed",
  3995.       "Ftype name isn't definite",
  3996. /*10*/"Current Ftype entry isn't defined",
  3997.       "Invalid copy mode",
  3998.       "Current unit doesn't have sites",
  3999.       "Can't update unit because unit is frozen",
  4000.       "Redefinition of site name isn't permitted (site name already exists)",
  4001.       "Site name isn't defined",
  4002.       "This is not a 3D-Kernel",
  4003.       "This unit has already a site with this name",
  4004.       "Can't delete site table entry because site is in use",
  4005.       "Current Ftype site isn't defined",
  4006. /*20*/"Ftype symbol isn't defined",
  4007.       "I/O error: ",
  4008.       "Creation of output file failed (line length limit exceeded)",
  4009.       "The network has not enough layers: ",
  4010.       "No Units defined",
  4011.       "Unexpected EOF",
  4012.       "Line length exceeded",
  4013.       "Incompatible file format",
  4014.       "Can't open file",
  4015.       "Syntax error",
  4016. /*30*/"Memory allocation error #01",
  4017.       "Topologic type invalid",
  4018.       "Symbol pattern invalid (must match [A-Za-z]^[|, ]*)",
  4019.       "Current unit doesn't have a site with this name",
  4020.       "No hidden units defined",
  4021.       "Network contains cycle(s): ",
  4022.       "Network contains dead unit(s): ",
  4023.       "Pattern file contains not the same no. of input units as the network",
  4024.       "Pattern file contains not the same no. of output units as the network",
  4025.       "No. of input units have changed",
  4026. /*40*/"No. of output units have changed",
  4027.       "No input units defined",
  4028.       "No output units defined",
  4029.       "No patterns defined",
  4030.       "In-Core patterns incompatible with current network (remove In-Core patterns before loading a new network)",
  4031.       "Invalid pattern number",
  4032.       "Invalid learning function",
  4033.       "Invalid parameters",
  4034.       "Invalid update function",
  4035.       "Invalid initialisation function",
  4036. /*50*/"Derivation function of the activation function doesn't exist",
  4037.       "Input unit(s) with input connection(s) to other units: ",
  4038.       "Output unit(s) with output connection(s) to other units: ",
  4039.       "Invalid topological sorting mode",
  4040.       "Learning function doesn't support sites",
  4041.       "Sites are not supported",
  4042.       "This isn't a MasPar Kernel",
  4043.       "Connection(s) between unit(s) in non-neighbour layers are not supported: ",
  4044.       "The network has too much layers: ",
  4045.       "The network layers aren't fully connected",
  4046. /*60*/"This operation isn't allowed in the parallel kernel mode",
  4047.       "Change of network type isn't possible in parallel kernel mode",
  4048.       "No current link defined",
  4049.       "No current unit defined",
  4050.       "Current unit doesn't have any inputs",
  4051.       "Invalid parameter in topologic definition section",
  4052.       "Creation of link between these units isn't permitted",
  4053.       "MasPar don't respond",
  4054.       "This function isn't implemented yet",
  4055.       "Kernel isn't in parallel mode",
  4056. /*70*/"MasPar ran out of memory",
  4057.       "MasPar communication error",
  4058.       "MasPar ran out of processors",
  4059.       "Missing default function (check function table)",
  4060.       "MasPar kernel doesn't support multiple unit output functions",
  4061.       "MasPar kernel doesn't support multiple unit activation functions",
  4062.       "The depth of the network doesn't fit to the learning function",
  4063.       "Wrong no of units in layer: ",
  4064.       "Unit is missing or not correctly connected: ",
  4065.       "Unit doesn't belong to a defined layer in the network: ",
  4066. /*80*/"Unit has wrong activation function: ",
  4067.       "Unit has wrong output function: ",
  4068.       "Unexpected site function at unit: ",
  4069.       "Unit is not expected to have sites: ",
  4070.       "Unit is expected to have sites: ",
  4071.       "Site missing at unit: ",
  4072.       "Unexpected link: ",
  4073.       "Missing link(s) to unit: ",
  4074.       "Link ends at wrong site of destination unit: ",
  4075.       "This network is not fitting the required topology",
  4076. /*90*/"Wrong beta parameter in unit bias value: ",
  4077.       "CC/RCC error: Topo_ptr_array is sorted in the wrong way", /*CC_ERROR1*/
  4078.       "CC/RCC error: There is no memory allocated",/*CC_ERROR2*/
  4079.       "CC/RCC error: Not enough memory to run Casscade",/*CC_ERROR3*/
  4080.       "RCC error: Hidden unit with more than one recurent link detected",/*CC_ERROR4*/
  4081.       "RCC error: Hidden unit without recurent link detected",/*CC_ERROR5*/
  4082.       "CC/RCC error: Hidden layer is not fitting the required topology",/*CC_ERROR6*/
  4083.       "RCC error: The first link of a hidden unit is not a recurent link",/*CC_ERROR7*/
  4084.       "RCC error: Special Unit with more than one recurent link detected",/*CC_ERROR8*/
  4085.       "RCC error: The first link of a special unit is not a recurent link",/*CC_ERROR9*/
  4086. /*100*/ "Wrong update function",/*CC_ERROR10*/
  4087.         "Wrong init function", /*CC_ERROR11*/
  4088.         "DLVQ error: There are empty classes",
  4089.         "DLVQ error: There exists a class lower than zero",
  4090.         "DLVQ error: Wrong no. of output units",
  4091.         "DLVQ error: This network is not fitting the required topology",
  4092.         "DLVQ error: There does not exist a unit for every class",
  4093.         "No more free pattern sets available",
  4094.         "No such pattern set defined",
  4095.         "No current pattern defined",
  4096. /*110*/ "Specified sub pattern does not fit into pattern",
  4097.         "No such pattern available",
  4098.         "No current pattern set defined",
  4099.         "Pattern (sub pattern) does not fit the network",
  4100.         "No sub pattern shifting scheme defined",
  4101.         "Pattern contains no output information",
  4102.         "New pattern does not fit into existing set"
  4103.     }; /* 116 error messages */
  4104.  
  4105.   static char    *ext_messages[] = {
  4106.       "SNNS-Kernel No Errors",
  4107.       "SNNS-Kernel Error: ",
  4108.       "SNNS-Kernel Network Topologic Error: "
  4109.       };
  4110.  
  4111.   int  NoOfMessages = (sizeof err_message) / (sizeof err_message[0]);
  4112.   static char  mesg[512], aux[512];
  4113.  
  4114.  
  4115.   if (error_code == 0)    return( ext_messages[0] );  /*    No errors  */
  4116.  
  4117.   error_code = abs( error_code );
  4118.   if ( error_code >= NoOfMessages )  error_code = 0;  /*  invalid error code  */
  4119.  
  4120.   switch (-error_code)
  4121.     {
  4122.     case KRERR_CYCLES:
  4123.     case KRERR_DEAD_UNITS:
  4124.     case KRERR_I_UNITS_CONNECT:
  4125.     case KRERR_O_UNITS_CONNECT:
  4126.     case KRERR_NOT_NEIGHBOUR_LAYER:
  4127.     case KRERR_ACT_FUNC:
  4128.     case KRERR_OUT_FUNC:
  4129.     case KRERR_SITE_FUNC:
  4130.     case KRERR_UNEXPECTED_SITES:
  4131.     case KRERR_UNEXPECTED_DIRECT_INPUTS:
  4132.     case KRERR_SITE_MISSING:
  4133.     case KRERR_UNEXPECTED_LINK:
  4134.     case KRERR_LINK_MISSING:
  4135.     case KRERR_LINK_TO_WRONG_SITE:
  4136.     case KRERR_PARAM_BETA:
  4137.     case KRERR_UNDETERMINED_UNIT:
  4138.  
  4139.       strcpy( mesg, ext_messages[2] );
  4140.       strcat( mesg, err_message[ error_code ] );
  4141.  
  4142.       switch (-error_code)
  4143.         {
  4144.         case KRERR_CYCLES:
  4145.           sprintf( aux, "%d cycle(s) in the network. ", topo_msg.no_of_cycles );
  4146.           strcat( mesg, aux );
  4147.           break;
  4148.         case KRERR_DEAD_UNITS:
  4149.           sprintf( aux, "%d dead unit(s) in the network. ", topo_msg.no_of_dead_units );
  4150.           strcat( mesg, aux );
  4151.           break;
  4152.  
  4153.         default: break;
  4154.       }
  4155.  
  4156.       strcat( mesg, krui_topo_err_msg() );
  4157.       return( mesg );
  4158.  
  4159.  
  4160.     case KRERR_FEW_LAYERS:
  4161.     case KRERR_MUCH_LAYERS:
  4162.     case KRERR_NOT_FULLY_CONNECTED:
  4163.       strcpy( mesg, ext_messages[2] );
  4164.       strcat( mesg, err_message[ error_code ] );
  4165.  
  4166.       switch (-error_code)
  4167.         {
  4168.         case KRERR_FEW_LAYERS:
  4169.           sprintf( aux, "Only %d layers found.", topo_msg.no_of_layers );
  4170.           break;
  4171.         case KRERR_MUCH_LAYERS:
  4172.           sprintf( aux, "%d layers found.", topo_msg.no_of_layers );
  4173.           break;
  4174.  
  4175.         default: break;
  4176.         }
  4177.  
  4178.       strcat( mesg, aux );
  4179.       return( mesg );
  4180.  
  4181.     case KRERR_NO_OF_UNITS_IN_LAYER:
  4182.        strcpy (mesg, ext_messages[2]);
  4183.        strcat (mesg, err_message [error_code]);
  4184.        sprintf (aux, "The name of the layer is: %s", topo_msg.name);
  4185.        strcat (mesg, aux);
  4186.        return (mesg);
  4187.  
  4188.     case KRERR_UNIT_MISSING:
  4189.        strcpy (mesg, ext_messages[2]);
  4190.        strcat (mesg, err_message [error_code]);
  4191.        sprintf (aux, "The missing unit is the %s unit.", topo_msg.name);
  4192.        strcat (mesg, aux);
  4193.        return (mesg);
  4194.  
  4195.  
  4196.  
  4197.     case KRERR_FILE_OPEN:
  4198.       lineno = 0;
  4199.  
  4200.     default:
  4201.       if (lineno != 0)
  4202.     {  /*  file I/O error  */
  4203.     strcpy( mesg, ext_messages[1] );
  4204.     sprintf( aux, "Loading file failed at line %d : ", lineno );
  4205.     strcat( mesg, aux );
  4206.     strcat( mesg, err_message[ error_code ] );
  4207.  
  4208.     lineno = 0;
  4209.     return( mesg );
  4210.       }
  4211.       else
  4212.     {  /*  standard error  */
  4213.     strcpy( mesg, ext_messages[1] );
  4214.     strcat( mesg, err_message[ error_code ] );
  4215.     return( mesg );
  4216.       }
  4217.     }
  4218. }
  4219.  
  4220.  
  4221. /* #############################################################
  4222.  
  4223.   Functions for the extern kernels
  4224.  
  4225. ############################################################# */
  4226. /*****************************************************************************
  4227.   FUNCTION : krui_setSpecialNetworkType
  4228.  
  4229.   PURPOSE  : Sets the topologic type of the current network.
  4230.              Returns an error if the topologic type of the current network  
  4231.              doesn't fit to this type.
  4232.              Topologic types are:
  4233.                - NET_TYPE_GENERAL
  4234.                  general purpose network type with no limitations
  4235.                - NET_TYPE_FF1
  4236.                  feedforward network with fully connected units in
  4237.                  neighbour layers
  4238.   NOTES    : 
  4239.  
  4240.   RETURNS  : 
  4241.   UPDATE   : 
  4242. ******************************************************************************/
  4243. krui_err  krui_setSpecialNetworkType(int net_type)
  4244. {
  4245.   (void) kr_setSpecialNetworkType( net_type );
  4246.  
  4247.   return( KernelErrorCode );
  4248. }
  4249. /*****************************************************************************
  4250.   FUNCTION :  krui_getSpecialNetworkType
  4251.  
  4252.   PURPOSE  : 
  4253.   NOTES    : 
  4254.  
  4255.   RETURNS  : Returns the special topologic type of the current network, if set.
  4256.   UPDATE   : 
  4257. ******************************************************************************/
  4258. int  krui_getSpecialNetworkType(void)
  4259. {
  4260.   return( kr_getSpecialNetworkType() );
  4261. }
  4262.  
  4263. /*****************************************************************************
  4264.   FUNCTION : krui_initInversion
  4265.  
  4266.   PURPOSE  : initialize net for inversion algorithm
  4267.   NOTES    :
  4268.   UPDATE   : 06.02.92
  4269. ******************************************************************************/
  4270. int krui_initInversion(void)
  4271. {
  4272.     return( kr_initInversion() );
  4273. }
  4274.  
  4275. /*****************************************************************************
  4276.   FUNCTION : krui_inv_forwardPass
  4277.  
  4278.   PURPOSE  : topological forward propagation of the inversion algorithm
  4279.   NOTES    :
  4280.   UPDATE   : 29.01.92
  4281. ******************************************************************************/
  4282. void  krui_inv_forwardPass(struct UnitList *inputs)
  4283. {
  4284.     kr_inv_forwardPass(inputs);
  4285. }
  4286.  
  4287.  
  4288. /*****************************************************************************
  4289.   FUNCTION : krui_inv_backwardPass
  4290.  
  4291.   PURPOSE  : Backward error propagation (topological) 
  4292.   NOTES    :
  4293.   UPDATE   : 04.02.92
  4294. *****************************************************************************/
  4295. double krui_inv_backwardPass(float learn, float delta_max, int *err_units, 
  4296.                  float ratio, struct UnitList *inputs,
  4297.                  struct UnitList *outputs)
  4298. {
  4299.     return(kr_inv_backwardPass(learn,delta_max,err_units,
  4300.                    ratio,inputs,outputs) ) ;
  4301. }
  4302.  
  4303.  
  4304. /* #############################################################
  4305.  
  4306.   Functions for the MasPar kernel
  4307.  
  4308. ############################################################# */
  4309.  
  4310. #ifdef MASPAR_KERNEL
  4311. /*****************************************************************************
  4312.   FUNCTION : krui_MasPar
  4313.  
  4314.   PURPOSE  : Connects and disconnects the MasPar.
  4315.              The mode switches are:  MASPAR_CONNECT and MASPAR_DISCONNECT.
  4316.   NOTES    : 
  4317.  
  4318.   RETURNS  : 
  4319.   UPDATE   : 
  4320. ******************************************************************************/
  4321. krui_err  krui_MasPar(int mode )
  4322. {
  4323.   return( kr_initMasPar( mode ) );
  4324. }
  4325. /*****************************************************************************
  4326.   FUNCTION : krui_getMasParStatus
  4327.  
  4328.   PURPOSE  : Returns the status of the MasPar.
  4329.   NOTES    : 
  4330.  
  4331.   RETURNS  : 
  4332.   UPDATE   : 
  4333. ******************************************************************************/
  4334. krui_err  krui_getMasParStatus(void)
  4335. {
  4336.   return( kr_getMasParStatus() );
  4337. }
  4338.  
  4339. /*****************************************************************************
  4340.   FUNCTION : krui_MasParBenchmark
  4341.  
  4342.   PURPOSE  : Perform benchmark tests
  4343.   NOTES    : 
  4344.  
  4345.   RETURNS  : 
  4346.   UPDATE   : 
  4347. ******************************************************************************/
  4348. krui_err  krui_MasParBenchmark(int func_type,int cycles,float  *result )
  4349. {
  4350.   float  parameterInArray[NO_OF_LEARN_PARAMS];
  4351.   float  *parameterOutArray;
  4352.   int  NoOfOutParams;
  4353.  
  4354.  
  4355.   parameterInArray[0] = (float) cycles;
  4356.   (void) kr_callNetworkFunction( func_type | BENCH_FUNC,
  4357.                          parameterInArray, 1,
  4358.                  ¶meterOutArray, &NoOfOutParams,
  4359.                  0, 0 );
  4360.  
  4361.   *result = parameterOutArray[0];
  4362.   return( KernelErrorCode );
  4363. }
  4364.  
  4365.  
  4366. #endif
  4367.  
  4368.  
  4369.  
  4370.  
  4371.  
  4372.  
  4373.  
  4374.  
  4375.  
  4376.